forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eth, eth/protocols/eth: added metadium message handlers
- Loading branch information
Showing
6 changed files
with
216 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package eth | ||
|
||
import ( | ||
"fmt" | ||
|
||
metaapi "github.com/ethereum/go-ethereum/metadium/api" | ||
metaminer "github.com/ethereum/go-ethereum/metadium/miner" | ||
) | ||
|
||
func handleGetPendingTxs(backend Backend, msg Decoder, peer *Peer) error { | ||
// not supported, just ignore it. | ||
return nil | ||
} | ||
|
||
func handleGetStatusEx(backend Backend, msg Decoder, peer *Peer) error { | ||
if !metaminer.AmPartner() || !metaminer.IsPartner(peer.ID()) { | ||
return nil | ||
} | ||
|
||
go func() { | ||
statusEx := metaapi.GetMinerStatus() | ||
statusEx.LatestBlockTd = backend.Chain().GetTd(statusEx.LatestBlockHash, | ||
statusEx.LatestBlockHeight.Uint64()) | ||
if err := peer.SendStatusEx(statusEx); err != nil { | ||
// ignore the error | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
func handleStatusEx(backend Backend, msg Decoder, peer *Peer) error { | ||
if !metaminer.AmPartner() || !metaminer.IsPartner(peer.ID()) { | ||
return nil | ||
} | ||
var status metaapi.MetadiumMinerStatus | ||
if err := msg.Decode(&status); err != nil { | ||
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err) | ||
} | ||
|
||
go func() { | ||
if _, td := peer.Head(); status.LatestBlockTd.Cmp(td) > 0 { | ||
peer.SetHead(status.LatestBlockHash, status.LatestBlockTd) | ||
} | ||
metaapi.GotStatusEx(&status) | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
func handleEtcdAddMember(backend Backend, msg Decoder, peer *Peer) error { | ||
if !metaminer.AmPartner() || !metaminer.IsPartner(peer.ID()) { | ||
return nil | ||
} | ||
|
||
go func() { | ||
cluster, _ := metaapi.EtcdAddMember(peer.ID()) | ||
if err := peer.SendEtcdCluster(cluster); err != nil { | ||
// ignore the error | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
|
||
func handleEtcdCluster(backend Backend, msg Decoder, peer *Peer) error { | ||
if !metaminer.AmPartner() || !metaminer.IsPartner(peer.ID()) { | ||
return nil | ||
} | ||
var cluster string | ||
if err := msg.Decode(&cluster); err != nil { | ||
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err) | ||
} | ||
|
||
go metaapi.GotEtcdCluster(cluster) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters