forked from relayooor/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block build trigger from beacon node api (ethereum#17)
* Add block build trigger from beacon node * remove empty block building Co-authored-by: avalonche <[email protected]>
- Loading branch information
Showing
11 changed files
with
296 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package builder | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/beacon" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/eth" | ||
"github.com/ethereum/go-ethereum/eth/catalyst" | ||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
type IEthereumService interface { | ||
BuildBlock(attrs *BuilderPayloadAttributes) *beacon.ExecutableDataV1 | ||
GetBlockByHash(hash common.Hash) *types.Block | ||
Synced() bool | ||
} | ||
|
||
type testEthereumService struct { | ||
synced bool | ||
testExecutableData *beacon.ExecutableDataV1 | ||
testBlock *types.Block | ||
} | ||
|
||
func (t *testEthereumService) BuildBlock(attrs *BuilderPayloadAttributes) *beacon.ExecutableDataV1 { | ||
return t.testExecutableData | ||
} | ||
|
||
func (t *testEthereumService) GetBlockByHash(hash common.Hash) *types.Block { return t.testBlock } | ||
|
||
func (t *testEthereumService) Synced() bool { return t.synced } | ||
|
||
type EthereumService struct { | ||
eth *eth.Ethereum | ||
} | ||
|
||
func NewEthereumService(eth *eth.Ethereum) *EthereumService { | ||
return &EthereumService{eth: eth} | ||
} | ||
|
||
func (s *EthereumService) BuildBlock(attrs *BuilderPayloadAttributes) *beacon.ExecutableDataV1 { | ||
// Send a request to generate a full block in the background. | ||
// The result can be obtained via the returned channel. | ||
resCh, err := s.eth.Miner().GetSealingBlockAsync(attrs.HeadHash, uint64(attrs.Timestamp), attrs.SuggestedFeeRecipient, attrs.GasLimit, attrs.Random, false) | ||
if err != nil { | ||
log.Error("Failed to create async sealing payload", "err", err) | ||
return nil | ||
} | ||
|
||
resultPayload := catalyst.NewPayload(resCh) | ||
executableData, _ := resultPayload.Resolve() | ||
return executableData | ||
} | ||
|
||
func (s *EthereumService) GetBlockByHash(hash common.Hash) *types.Block { | ||
return s.eth.BlockChain().GetBlockByHash(hash) | ||
} | ||
|
||
func (s *EthereumService) Synced() bool { | ||
return s.eth.Synced() | ||
} |
Oops, something went wrong.