use patched plugeth GetContractCode

This commit is contained in:
Roy Crihfield 2023-06-22 15:17:01 +08:00
parent 0d9a5f3828
commit e24178a8a9
2 changed files with 8 additions and 36 deletions

View File

@ -3,9 +3,7 @@ package statediff
import (
"context"
"encoding/json"
"errors"
"math/big"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
@ -32,26 +30,16 @@ type BlockChain interface {
StateCache() adapt.StateView
}
// CodeStore stores contract code hashes to data in a synchronized map
type CodeStore struct {
code map[plugeth.Hash][]byte
codeMtx sync.RWMutex
}
// pluginBlockChain adapts the plugeth Backend to the blockChain interface
type pluginBlockChain struct {
restricted.Backend
ctx context.Context
code *CodeStore
}
var _ BlockChain = (*pluginBlockChain)(nil)
func NewPluginBlockChain(backend restricted.Backend, code *CodeStore) BlockChain {
func NewPluginBlockChain(backend restricted.Backend) BlockChain {
return &pluginBlockChain{
Backend: backend,
ctx: context.Background(),
code: code,
}
}
@ -132,21 +120,5 @@ func (p *pluginStateView) OpenTrie(root common.Hash) (adapt.StateTrie, error) {
}
func (p *pluginStateView) ContractCode(hash common.Hash) ([]byte, error) {
return p.backend.code.Get(plugeth.Hash(hash))
}
func (b *CodeStore) Get(hash plugeth.Hash) ([]byte, error) {
b.codeMtx.RLock()
defer b.codeMtx.RUnlock()
code, has := b.code[hash]
if !has {
return nil, errors.New("code not found")
}
return []byte(string(code)), nil
}
func (b *CodeStore) Set(hash plugeth.Hash, code []byte) {
b.codeMtx.Lock()
defer b.codeMtx.Unlock()
b.code[hash] = code
return p.backend.GetContractCode(plugeth.Hash(hash))
}

View File

@ -20,7 +20,6 @@ var (
gethContext core.Context
service *statediff.Service
blockchain statediff.BlockChain
codeStore statediff.CodeStore
)
func Initialize(ctx core.Context, pl core.PluginLoader, logger core.Logger) {
@ -48,7 +47,7 @@ func InitializeNode(stack core.Node, b core.Backend) {
return
}
serviceConfig := GetConfig()
blockchain = statediff.NewPluginBlockChain(backend, &codeStore)
blockchain = statediff.NewPluginBlockChain(backend)
var indexer interfaces.StateDiffIndexer
if serviceConfig.IndexerConfig != nil {
@ -101,7 +100,8 @@ func StateUpdate(
return
}
for hash, code := range codeUpdates {
codeStore.Set(hash, code)
}
// for hash, code := range codeUpdates {
// log.Debug("UPDATING CODE", "hash", hash)
// codeStore.Set(hash, code)
// }
}