Merge remote-tracking branch 'origin/develop' into feature/old-consensus-engine

This commit is contained in:
philip-morlier
2023-06-13 22:52:01 -07:00
255 changed files with 2797 additions and 2450 deletions
@@ -11,10 +11,12 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
gcore "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
@@ -460,3 +462,32 @@ func (b *Backend) ChainConfig() *params.ChainConfig {
}
return b.chainConfig
}
func (b *Backend) GetTrie(h core.Hash) (core.Trie, error) {
tr, err := trie.NewStateTrie(trie.TrieID(common.Hash(h)), trie.NewDatabase(b.b.ChainDb()))
if err != nil {
return nil, err
}
return NewWrappedTrie(tr), nil
}
func (b *Backend) GetAccountTrie(stateRoot core.Hash, account core.Address) (core.Trie, error) {
tr, err := b.GetTrie(stateRoot)
if err != nil {
return nil, err
}
act, err := tr.GetAccount(account)
if err != nil {
return nil, err
}
acTr, err := trie.NewStateTrie(trie.StorageTrieID(common.Hash(stateRoot), crypto.Keccak256Hash(account[:]), common.Hash(act.Root)), trie.NewDatabase(b.b.ChainDb()))
if err != nil {
return nil, err
}
return NewWrappedTrie(acTr), nil
}
@@ -0,0 +1,101 @@
package backendwrapper
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/trie"
"github.com/openrelayxyz/plugeth-utils/core"
)
type WrappedTrie struct {
t state.Trie
}
func NewWrappedTrie(t state.Trie) core.Trie {
return &WrappedTrie{t}
}
func (t *WrappedTrie) GetKey(b []byte) []byte {
return t.t.GetKey(b)
}
func (t *WrappedTrie) GetAccount(address core.Address) (*core.StateAccount, error) {
act, err := t.t.GetAccount(common.Address(address))
if err != nil {
return nil, err
}
return &core.StateAccount{
Nonce: act.Nonce,
Balance: act.Balance,
Root: core.Hash(act.Root),
CodeHash: act.CodeHash,
}, nil
}
func (t *WrappedTrie) Hash() core.Hash {
return core.Hash(t.t.Hash())
}
func (t *WrappedTrie) NodeIterator(startKey []byte) core.NodeIterator {
itr := t.t.NodeIterator(startKey)
return &WrappedNodeIterator{itr}
}
func (t *WrappedTrie) Prove(key []byte, fromLevel uint, proofDb core.KeyValueWriter) error {
return nil
}
type WrappedNodeIterator struct {
n trie.NodeIterator
}
func (n WrappedNodeIterator) Next(b bool) bool {
return n.n.Next(b)
}
func (n WrappedNodeIterator) Error() error {
return n.n.Error()
}
func (n WrappedNodeIterator) Hash() core.Hash {
return core.Hash(n.n.Hash())
}
func (n WrappedNodeIterator) Parent() core.Hash {
return core.Hash(n.n.Parent())
}
func (n WrappedNodeIterator) Path() []byte {
return n.n.Path()
}
func (n WrappedNodeIterator) NodeBlob() []byte {
return n.n.NodeBlob()
}
func (n WrappedNodeIterator) Leaf() bool {
return n.n.Leaf()
}
func (n WrappedNodeIterator) LeafKey() []byte {
return n.n.LeafKey()
}
func (n WrappedNodeIterator) LeafBlob() []byte {
return n.n.LeafBlob()
}
func (n WrappedNodeIterator) LeafProof() [][]byte {
return n.n.LeafProof()
}
func (n WrappedNodeIterator) AddResolver(c core.NodeResolver) {
n.n.AddResolver(WrappedNodeResolver(c))
}
func WrappedNodeResolver(fn core.NodeResolver) trie.NodeResolver {
return func(owner common.Hash, path []byte, hash common.Hash) []byte {
return fn(core.Hash(owner), path, core.Hash(hash) )
}
}
-41
View File
@@ -9,7 +9,6 @@ import (
"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"
@@ -125,28 +124,11 @@ func gethToUtilsWithdrawals(withdrawals []*types.Withdrawal) []*ptypes.Withdrawa
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 {
@@ -169,27 +151,6 @@ func utilsToGethTransactions(transactions []*ptypes.Transaction) []*types.Transa
}
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))
@@ -210,7 +171,6 @@ func gethToUtilsBlockChan(ch chan<- *types.Block) chan<- *ptypes.Block {
for block := range pchan {
ch <- utilsToGethBlock(block)
}
// close(ch)
}()
return pchan
}
@@ -430,7 +390,6 @@ func (ew *engineWrapper) Prepare(chain consensus.ChainHeaderReader, header *type
if err := ew.engine.Prepare(&WrappedHeaderReader{chain, nil}, uHeader); err != nil {
return err
}
// header.Difficulty = uHeader.Difficulty
*header = *utilsToGethHeader(uHeader)
return nil
}
+1
View File
@@ -198,6 +198,7 @@ func (w *WrappedStateDB) SlotInAccessList(addr core.Address, slot core.Hash) (ad
func (w *WrappedStateDB) IntermediateRoot(deleteEmptyObjects bool) core.Hash {
return core.Hash(w.s.IntermediateRoot(deleteEmptyObjects))
}
type Node struct {
n *node.Node