From 7434ccb8c861e3f25e94a9fe2ebb1393633a7a66 Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Mon, 12 Jun 2023 09:52:46 -0700 Subject: [PATCH] Initial commit of stand alone consensus engine work. --- cmd/geth/main.go | 3 +- cmd/geth/plugin_hooks.go | 18 + eth/ethconfig/config.go | 6 + eth/ethconfig/plugin_hooks.go | 44 ++ plugins/wrappers/backendwrapper/dbwrapper.go | 4 + plugins/wrappers/engine/enginewrapper.go | 468 +++++++++++++++++++ plugins/wrappers/wrappers.go | 6 + 7 files changed, 548 insertions(+), 1 deletion(-) create mode 100644 eth/ethconfig/plugin_hooks.go create mode 100644 plugins/wrappers/engine/enginewrapper.go diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b750c55b2..40e6b6cfe 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -355,8 +355,9 @@ func geth(ctx *cli.Context) error { defer stack.Close() defer pluginsOnShutdown() stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend)) - //end PluGeth code injection startNode(ctx, stack, backend, false) + pluginHookTester() + //end PluGeth code injection stack.Wait() return nil } diff --git a/cmd/geth/plugin_hooks.go b/cmd/geth/plugin_hooks.go index 80187a028..73ff14884 100644 --- a/cmd/geth/plugin_hooks.go +++ b/cmd/geth/plugin_hooks.go @@ -102,3 +102,21 @@ func pluginsOnShutdown() { } OnShutdown(plugins.DefaultPluginLoader) } + +func HookTester(pl *plugins.PluginLoader) { + fnList := pl.Lookup("HookTester", func(item interface{}) bool { + _, ok := item.(func()) + return ok + }) + for _, fni := range fnList { + fni.(func())() + } +} + +func pluginHookTester() { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting HookTester, but default PluginLoader has not been initialized") + return + } + HookTester(plugins.DefaultPluginLoader) +} \ No newline at end of file diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index db686c5d0..5f421825d 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -212,6 +212,12 @@ type Config struct { // CreateConsensusEngine creates a consensus engine for the given chain configuration. func CreateConsensusEngine(stack *node.Node, ethashConfig *ethash.Config, cliqueConfig *params.CliqueConfig, notify []string, noverify bool, db ethdb.Database) consensus.Engine { // If proof-of-authority is requested, set it up + //begin PluGeth code injection + if engine := pluginGetEngine(stack, notify, noverify, db); engine != nil { + log.Debug("returning plugin consensus engine") + return engine + } + //end PluGeth code injection var engine consensus.Engine if cliqueConfig != nil { engine = clique.New(cliqueConfig, db) diff --git a/eth/ethconfig/plugin_hooks.go b/eth/ethconfig/plugin_hooks.go new file mode 100644 index 000000000..8f09f6069 --- /dev/null +++ b/eth/ethconfig/plugin_hooks.go @@ -0,0 +1,44 @@ +package ethconfig + +import ( + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins" + "github.com/ethereum/go-ethereum/plugins/wrappers" + wengine "github.com/ethereum/go-ethereum/plugins/wrappers/engine" + "github.com/ethereum/go-ethereum/plugins/wrappers/backendwrapper" + "github.com/openrelayxyz/plugeth-utils/core" + "github.com/openrelayxyz/plugeth-utils/restricted" + + "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/node" + + pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus" +) + + + +func PluginGetEngine(pl *plugins.PluginLoader, stack *node.Node, notify []string, noverify bool, db ethdb.Database) consensus.Engine { + fnList := pl.Lookup("CreateEngine", func(item interface{}) bool { + _, ok := item.(func(core.Node, []string, bool, restricted.Database) pconsensus.Engine) + return ok + }) + for _, fni := range fnList { + if fn, ok := fni.(func(core.Node, []string, bool, restricted.Database) pconsensus.Engine); ok { + if engine := fn(wrappers.NewNode(stack), notify, noverify, backendwrapper.NewDB(db)); engine != nil { + wrappedEngine := wengine.NewWrappedEngine(engine) + return wrappedEngine + } + + } + } + return nil +} + +func pluginGetEngine(stack *node.Node, notify []string, noverify bool, db ethdb.Database) consensus.Engine { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting GetEngine, but default PluginLoader has not been initialized") + return nil + } + return PluginGetEngine(plugins.DefaultPluginLoader, stack, notify, noverify, db) +} \ No newline at end of file diff --git a/plugins/wrappers/backendwrapper/dbwrapper.go b/plugins/wrappers/backendwrapper/dbwrapper.go index 30b0d7aa5..8af502034 100644 --- a/plugins/wrappers/backendwrapper/dbwrapper.go +++ b/plugins/wrappers/backendwrapper/dbwrapper.go @@ -11,6 +11,10 @@ type dbWrapper struct { db ethdb.Database } +func NewDB(d ethdb.Database) restricted.Database { + return &dbWrapper{d} +} + func (d *dbWrapper) Has(key []byte) (bool, error) { return d.db.Has(key) } func (d *dbWrapper) Get(key []byte) ([]byte, error) { return d.db.Get(key) } func (d *dbWrapper) Put(key []byte, value []byte) error { return d.db.Put(key, value) } diff --git a/plugins/wrappers/engine/enginewrapper.go b/plugins/wrappers/engine/enginewrapper.go new file mode 100644 index 000000000..f8aacc60d --- /dev/null +++ b/plugins/wrappers/engine/enginewrapper.go @@ -0,0 +1,468 @@ +package engine + +import ( + "fmt" + "math/big" + "reflect" + "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state" + // "github.com/ethereum/go-ethereum/trie" + "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins/wrappers" + "github.com/openrelayxyz/plugeth-utils/core" + ptypes "github.com/openrelayxyz/plugeth-utils/restricted/types" + pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus" + pparams "github.com/openrelayxyz/plugeth-utils/restricted/params" +) + + +func gethToUtilsHeader(header *types.Header) *ptypes.Header { + if header == nil { return nil } + return &ptypes.Header{ + ParentHash: core.Hash(header.ParentHash), + UncleHash: core.Hash(header.UncleHash), + Coinbase: core.Address(header.Coinbase), + Root: core.Hash(header.Root), + TxHash: core.Hash(header.TxHash), + ReceiptHash: core.Hash(header.ReceiptHash), + Bloom: ptypes.Bloom(header.Bloom), + Difficulty: header.Difficulty, + Number: header.Number, + GasLimit: header.GasLimit, + GasUsed: header.GasUsed, + Time: header.Time, + Extra: header.Extra, + MixDigest: core.Hash(header.MixDigest), + Nonce: ptypes.BlockNonce(header.Nonce), + BaseFee: header.BaseFee, + WithdrawalsHash: (*core.Hash)(header.WithdrawalsHash), + } +} +func utilsToGethHeader(header *ptypes.Header) *types.Header { + if header == nil { return nil } + return &types.Header{ + ParentHash: common.Hash(header.ParentHash), + UncleHash: common.Hash(header.UncleHash), + Coinbase: common.Address(header.Coinbase), + Root: common.Hash(header.Root), + TxHash: common.Hash(header.TxHash), + ReceiptHash: common.Hash(header.ReceiptHash), + Bloom: types.Bloom(header.Bloom), + Difficulty: header.Difficulty, + Number: header.Number, + GasLimit: header.GasLimit, + GasUsed: header.GasUsed, + Time: header.Time, + Extra: header.Extra, + MixDigest: common.Hash(header.MixDigest), + Nonce: types.BlockNonce(header.Nonce), + BaseFee: header.BaseFee, + WithdrawalsHash: (*common.Hash)(header.WithdrawalsHash), + } +} + +func gethToUtilsTransactions(transactions []*types.Transaction) []*ptypes.Transaction { + if transactions == nil { return nil } + txs := make([]*ptypes.Transaction, len(transactions)) + for i, tx := range transactions { + bin, err := tx.MarshalBinary() + if err != nil { panic (err) } + txs[i] = &ptypes.Transaction{} + txs[i].UnmarshalBinary(bin) + } + return txs +} + +func gethToUtilsHeaders(headers []*types.Header) []*ptypes.Header { + if headers == nil { return nil } + pheaders := make([]*ptypes.Header, len(headers)) + for i, header := range headers { + pheaders[i] = gethToUtilsHeader(header) + } + return pheaders +} + +func gethToUtilsReceipts(receipts []*types.Receipt) []*ptypes.Receipt { + if receipts == nil { return nil } + preceipts := make([]*ptypes.Receipt, len(receipts)) + for i, receipt := range receipts { + preceipts[i] = &ptypes.Receipt{ + Type: receipt.Type, + PostState: receipt.PostState, + Status: receipt.Status, + CumulativeGasUsed: receipt.CumulativeGasUsed, + Bloom: ptypes.Bloom(receipt.Bloom), + Logs: gethToUtilsLogs(receipt.Logs), + TxHash: core.Hash(receipt.TxHash), + ContractAddress: core.Address(receipt.ContractAddress), + GasUsed: receipt.GasUsed, + BlockHash: core.Hash(receipt.BlockHash), + BlockNumber: receipt.BlockNumber, + TransactionIndex: receipt.TransactionIndex, + } + } + return preceipts +} + +func gethToUtilsWithdrawals(withdrawals []*types.Withdrawal) []*ptypes.Withdrawal { + if withdrawals == nil { return nil } + pwithdrawals := make([]*ptypes.Withdrawal, len(withdrawals)) + for i, withdrawal := range withdrawals { + pwithdrawals[i] = &ptypes.Withdrawal{ + Index: withdrawal.Index, + Validator: withdrawal.Validator, + Address: core.Address(withdrawal.Address), + Amount: withdrawal.Amount, + } + } + return pwithdrawals +} + +func gethToUtilsBlock(block *types.Block) *ptypes.Block { + if block == nil { return nil } + return ptypes.NewBlockWithHeader(gethToUtilsHeader(block.Header())).WithBody(gethToUtilsTransactions(block.Transactions()), gethToUtilsHeaders(block.Uncles())).WithWithdrawals(gethToUtilsWithdrawals(block.Withdrawals())) + + // NewBlockWithWithdrawals( + // gethToUtilsHeader(block.Header()), + // gethToUtilsTransactions(block.Transactions()), + // gethToUtilsHeaders(block.Uncles()), + // gethToUtilsReceipts(block.Receipts()), + // gethToUtilsWithdrawals(block.Withdrawals()), + // &hasherWrapper{trie.NewStackTrie(nil)}, + // ) +} + +func utilsToGethBlock(block *ptypes.Block) *types.Block { + if block == nil { return nil } + return types.NewBlockWithHeader(utilsToGethHeader(block.Header())).WithBody(utilsToGethTransactions(block.Transactions()), utilsToGethHeaders(block.Uncles())).WithWithdrawals(utilsToGethWithdrawals(block.Withdrawals())) + // return types.NewBlockWithWithdrawals( + // utilsToGethHeader(block.Header()), + // utilsToGethTransactions(block.Transactions()), + // utilsToGethHeaders(block.Uncles()), + // utilsToGethReceipts(block.Receipts()), + // utilsToGethWithdrawals(block.Withdrawals()), + // trie.NewStackTrie(nil), + // ) +} + +func utilsToGethHeaders(headers []*ptypes.Header) []*types.Header { + if headers == nil { return nil } + pheaders := make([]*types.Header, len(headers)) + for i, header := range headers { + pheaders[i] = utilsToGethHeader(header) + } + return pheaders +} + +func utilsToGethTransactions(transactions []*ptypes.Transaction) []*types.Transaction { + if transactions == nil { return nil } + txs := make([]*types.Transaction, len(transactions)) + for i, tx := range transactions { + bin, err := tx.MarshalBinary() + if err != nil { panic (err) } + txs[i] = &types.Transaction{} + txs[i].UnmarshalBinary(bin) + } + return txs +} +// func utilsToGethReceipts(receipts []*ptypes.Receipt) []*types.Receipt { +// if receipts == nil { return nil } +// preceipts := make([]*types.Receipt, len(receipts)) +// for i, receipt := range receipts { +// preceipts[i] = &types.Receipt{ +// Type: receipt.Type, +// PostState: receipt.PostState, +// Status: receipt.Status, +// CumulativeGasUsed: receipt.CumulativeGasUsed, +// Bloom: types.Bloom(receipt.Bloom), +// Logs: utilsToGethLogs(receipt.Logs), +// TxHash: common.Hash(receipt.TxHash), +// ContractAddress: common.Address(receipt.ContractAddress), +// GasUsed: receipt.GasUsed, +// BlockHash: common.Hash(receipt.BlockHash), +// BlockNumber: receipt.BlockNumber, +// TransactionIndex: receipt.TransactionIndex, +// } +// } +// return preceipts +// } +func utilsToGethWithdrawals(withdrawals []*ptypes.Withdrawal) []*types.Withdrawal { + if withdrawals == nil { return nil } + pwithdrawals := make([]*types.Withdrawal, len(withdrawals)) + for i, withdrawal := range withdrawals { + pwithdrawals[i] = &types.Withdrawal{ + Index: withdrawal.Index, + Validator: withdrawal.Validator, + Address: common.Address(withdrawal.Address), + Amount: withdrawal.Amount, + } + } + return pwithdrawals +} + +func gethToUtilsBlockChan(ch chan<- *types.Block) chan<- *ptypes.Block { + pchan := make(chan *ptypes.Block) + go func() { + for block := range pchan { + ch <- utilsToGethBlock(block) + } + // close(ch) + }() + return pchan +} + +func gethToUtilsLog(logRecord *types.Log) *ptypes.Log { + if logRecord == nil { return nil } + topics := make([]core.Hash, len(logRecord.Topics)) + for i, t := range logRecord.Topics { + topics[i] = core.Hash(t) + } + return &ptypes.Log{ + Address: core.Address(logRecord.Address), + Topics: topics, + Data: logRecord.Data, + BlockNumber: logRecord.BlockNumber, + TxHash: core.Hash(logRecord.TxHash), + TxIndex: logRecord.TxIndex, + BlockHash: core.Hash(logRecord.BlockHash), + Index: logRecord.Index, + Removed: logRecord.Removed, + } +} + +func utilsToGethLog(logRecord *ptypes.Log) *types.Log { + if logRecord == nil { return nil } + topics := make([]common.Hash, len(logRecord.Topics)) + for i, t := range logRecord.Topics { + topics[i] = common.Hash(t) + } + return &types.Log{ + Address: common.Address(logRecord.Address), + Topics: topics, + Data: logRecord.Data, + BlockNumber: logRecord.BlockNumber, + TxHash: common.Hash(logRecord.TxHash), + TxIndex: logRecord.TxIndex, + BlockHash: common.Hash(logRecord.BlockHash), + Index: logRecord.Index, + Removed: logRecord.Removed, + } +} + +func gethToUtilsLogs(logs []*types.Log) []*ptypes.Log { + result := make([]*ptypes.Log, len(logs)) + for i, logRecord := range logs { + result[i] = gethToUtilsLog(logRecord) + } + return result +} + +func utilsToGethLogs(logs []*ptypes.Log) []*types.Log { + result := make([]*types.Log, len(logs)) + for i, logRecord := range logs { + result[i] = utilsToGethLog(logRecord) + } + return result +} + + +func convertAndSet(a, b reflect.Value) (err error) { + defer func() { + if recover() != nil { + fmt.Errorf("error converting: %v", err.Error()) + } + }() + a.Set(b.Convert(a.Type())) + return nil +} + +func gethToUtilsConfig(gcfg *params.ChainConfig) *pparams.ChainConfig { + cfg := &pparams.ChainConfig{} + nval := reflect.ValueOf(gcfg) + ntype := nval.Elem().Type() + lval := reflect.ValueOf(cfg) + for i := 0; i < nval.Elem().NumField(); i++ { + field := ntype.Field(i) + v := nval.Elem().FieldByName(field.Name) + lv := lval.Elem().FieldByName(field.Name) + log.Info("Checking value for", "field", field.Name) + if lv.Kind() != reflect.Invalid { + // If core.ChainConfig doesn't have this field, skip it. + if v.Type() == lv.Type() && lv.CanSet() { + lv.Set(v) + } else { + convertAndSet(lv, v) + } + } + } + return cfg +} + +type WrappedHeaderReader struct { + chr consensus.ChainHeaderReader + cfg *pparams.ChainConfig +} + +func (whr *WrappedHeaderReader) Config() *pparams.ChainConfig { + if whr.cfg == nil { + whr.cfg = gethToUtilsConfig(whr.chr.Config()) + } + return whr.cfg +} + +// CurrentHeader retrieves the current header from the local chain. +func (whr *WrappedHeaderReader) CurrentHeader() *ptypes.Header { + return gethToUtilsHeader(whr.chr.CurrentHeader()) +} + +// GetHeader retrieves a block header from the database by hash and number. +func (whr *WrappedHeaderReader) GetHeader(hash core.Hash, number uint64) *ptypes.Header { + return gethToUtilsHeader(whr.chr.GetHeader(common.Hash(hash), number)) +} + +// GetHeaderByNumber retrieves a block header from the database by number. +func (whr *WrappedHeaderReader) GetHeaderByNumber(number uint64) *ptypes.Header { + return gethToUtilsHeader(whr.chr.GetHeaderByNumber(number)) +} + +// GetHeaderByHash retrieves a block header from the database by its hash. +func (whr *WrappedHeaderReader) GetHeaderByHash(hash core.Hash) *ptypes.Header { + return gethToUtilsHeader(whr.chr.GetHeaderByHash(common.Hash(hash))) +} + +// GetTd retrieves the total difficulty from the database by hash and number. +func (whr *WrappedHeaderReader) GetTd(hash core.Hash, number uint64) *big.Int { + return whr.chr.GetTd(common.Hash(hash), number) +} + + +type WrappedChainReader struct { + chr consensus.ChainReader + cfg *pparams.ChainConfig +} + +func (whr *WrappedChainReader) Config() *pparams.ChainConfig { + // We're using the reflect library to copy data from params.ChainConfig to + // pparams.ChainConfig, so this function shouldn't need to be touched for + // simple changes to ChainConfig (though pparams.ChainConfig may need to be + // updated). Note that this probably won't carry over consensus engine data. + if whr.cfg == nil { + whr.cfg = gethToUtilsConfig(whr.chr.Config()) + } + return whr.cfg +} + +// CurrentHeader retrieves the current header from the local chain. +func (whr *WrappedChainReader) CurrentHeader() *ptypes.Header { + return gethToUtilsHeader(whr.chr.CurrentHeader()) +} + +// GetHeader retrieves a block header from the database by hash and number. +func (whr *WrappedChainReader) GetHeader(hash core.Hash, number uint64) *ptypes.Header { + return gethToUtilsHeader(whr.chr.GetHeader(common.Hash(hash), number)) +} + +// GetHeaderByNumber retrieves a block header from the database by number. +func (whr *WrappedChainReader) GetHeaderByNumber(number uint64) *ptypes.Header { + return gethToUtilsHeader(whr.chr.GetHeaderByNumber(number)) +} + +// GetHeaderByHash retrieves a block header from the database by its hash. +func (whr *WrappedChainReader) GetHeaderByHash(hash core.Hash) *ptypes.Header { + return gethToUtilsHeader(whr.chr.GetHeaderByHash(common.Hash(hash))) +} + +// GetTd retrieves the total difficulty from the database by hash and number. +func (whr *WrappedChainReader) GetTd(hash core.Hash, number uint64) *big.Int { + return whr.chr.GetTd(common.Hash(hash), number) +} + +func (whr *WrappedChainReader) GetBlock(hash core.Hash, number uint64) *ptypes.Block { + return gethToUtilsBlock(whr.chr.GetBlock(common.Hash(hash), number)) +} + +type hasherWrapper struct { + th types.TrieHasher +} +func (hw *hasherWrapper) Reset() { + hw.th.Reset() +} +func (hw *hasherWrapper) Update(a, b []byte) { + hw.th.Update(a, b) +} +func (hw *hasherWrapper) Hash() core.Hash { + return core.Hash(hw.th.Hash()) +} + +type engineWrapper struct { + engine pconsensus.Engine +} + +func NewWrappedEngine(e pconsensus.Engine) consensus.Engine { + return &engineWrapper { + engine: e, + } +} + +func (ew *engineWrapper) Author(header *types.Header) (common.Address, error) { + addr, err := ew.engine.Author(gethToUtilsHeader(header)) + return common.Address(addr), err +} +func (ew *engineWrapper) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error { + return ew.engine.VerifyHeader(&WrappedHeaderReader{chain, nil}, gethToUtilsHeader(header), seal) +} +func (ew *engineWrapper) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) { + pheaders := make([]*ptypes.Header, len(headers)) + for i, header := range headers { + pheaders[i] = gethToUtilsHeader(header) + } + return ew.engine.VerifyHeaders(&WrappedHeaderReader{chain, nil}, pheaders, seals) +} +func (ew *engineWrapper) VerifyUncles(chain consensus.ChainReader, block *types.Block) error { + return ew.engine.VerifyUncles(&WrappedChainReader{chain, nil}, gethToUtilsBlock(block)) +} +func (ew *engineWrapper) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error { + uHeader := gethToUtilsHeader(header) + if err := ew.engine.Prepare(&WrappedHeaderReader{chain, nil}, uHeader); err != nil { + return err + } + // header.Difficulty = uHeader.Difficulty + *header = *utilsToGethHeader(uHeader) + return nil +} +func (ew *engineWrapper) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) { + ew.engine.Finalize(&WrappedHeaderReader{chain, nil}, gethToUtilsHeader(header), wrappers.NewWrappedStateDB(state), gethToUtilsTransactions(txs), gethToUtilsHeaders(uncles), gethToUtilsWithdrawals(withdrawals)) +} +func (ew *engineWrapper) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt, withdrawals []*types.Withdrawal) (*types.Block, error) { + block, err := ew.engine.FinalizeAndAssemble(&WrappedHeaderReader{chain, nil}, gethToUtilsHeader(header), wrappers.NewWrappedStateDB(state), gethToUtilsTransactions(txs), gethToUtilsHeaders(uncles), gethToUtilsReceipts(receipts), gethToUtilsWithdrawals(withdrawals)) + return utilsToGethBlock(block), err +} +func (ew *engineWrapper) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { + return ew.engine.Seal(&WrappedHeaderReader{chain, nil}, gethToUtilsBlock(block), gethToUtilsBlockChan(results), stop) +} +func (ew *engineWrapper) SealHash(header *types.Header) common.Hash { + return common.Hash(ew.engine.SealHash(gethToUtilsHeader(header))) +} +func (ew *engineWrapper) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int { + return ew.engine.CalcDifficulty(&WrappedHeaderReader{chain, nil}, time, gethToUtilsHeader(parent)) +} +func (ew *engineWrapper) APIs(chain consensus.ChainHeaderReader) []rpc.API { + papis := ew.engine.APIs(&WrappedHeaderReader{chain, nil}) + apis := make([]rpc.API, len(papis)) + for i, api := range papis { + apis[i] = rpc.API{ + Namespace: api.Namespace, + Version: api.Version, + Service: api.Service, + Public: api.Public, + } + } + return apis +} +func (ew *engineWrapper) Close() error { + return ew.engine.Close() +} diff --git a/plugins/wrappers/wrappers.go b/plugins/wrappers/wrappers.go index 5458cd4a5..e2ca48684 100644 --- a/plugins/wrappers/wrappers.go +++ b/plugins/wrappers/wrappers.go @@ -194,6 +194,12 @@ func (w *WrappedStateDB) SlotInAccessList(addr core.Address, slot core.Hash) (ad return w.s.SlotInAccessList(common.Address(addr), common.Hash(slot)) } +// IntermediateRoot(deleteEmptyObjects bool) common.Hash +func (w *WrappedStateDB) IntermediateRoot(deleteEmptyObjects bool) core.Hash { + return core.Hash(w.s.IntermediateRoot(deleteEmptyObjects)) +} + + type Node struct { n *node.Node }