2021-07-12 19:45:42 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2022-03-14 15:50:54 +00:00
|
|
|
"fmt"
|
2021-09-01 20:34:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins"
|
2023-09-13 19:57:48 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2021-09-03 22:20:49 +00:00
|
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
2021-07-12 19:45:42 +00:00
|
|
|
)
|
|
|
|
|
2022-03-14 15:50:54 +00:00
|
|
|
type pluginSnapshot struct {
|
|
|
|
root common.Hash
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *pluginSnapshot) Root() common.Hash {
|
|
|
|
return s.root
|
|
|
|
}
|
|
|
|
|
2023-09-13 19:57:48 +00:00
|
|
|
func (s *pluginSnapshot) Account(hash common.Hash) (*types.SlimAccount, error) {
|
2022-03-14 15:50:54 +00:00
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *pluginSnapshot) AccountRLP(hash common.Hash) ([]byte, error) {
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *pluginSnapshot) Storage(accountHash, storageHash common.Hash) ([]byte, error) {
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
|
|
|
}
|
|
|
|
|
2021-09-20 15:44:07 +00:00
|
|
|
func PluginStateUpdate(pl *plugins.PluginLoader, blockRoot, parentRoot common.Hash, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) {
|
2021-09-01 20:34:03 +00:00
|
|
|
fnList := pl.Lookup("StateUpdate", func(item interface{}) bool {
|
2021-09-20 15:44:07 +00:00
|
|
|
_, ok := item.(func(core.Hash, core.Hash, map[core.Hash]struct{}, map[core.Hash][]byte, map[core.Hash]map[core.Hash][]byte, map[core.Hash][]byte))
|
2021-09-01 20:34:03 +00:00
|
|
|
return ok
|
|
|
|
})
|
2021-09-03 22:20:49 +00:00
|
|
|
coreDestructs := make(map[core.Hash]struct{})
|
|
|
|
for k, v := range destructs {
|
|
|
|
coreDestructs[core.Hash(k)] = v
|
|
|
|
}
|
|
|
|
coreAccounts := make(map[core.Hash][]byte)
|
|
|
|
for k, v := range accounts {
|
|
|
|
coreAccounts[core.Hash(k)] = v
|
|
|
|
}
|
|
|
|
coreStorage := make(map[core.Hash]map[core.Hash][]byte)
|
|
|
|
for k, v := range storage {
|
|
|
|
coreStorage[core.Hash(k)] = make(map[core.Hash][]byte)
|
|
|
|
for h, d := range v {
|
|
|
|
coreStorage[core.Hash(k)][core.Hash(h)] = d
|
|
|
|
}
|
|
|
|
}
|
2021-09-20 15:44:07 +00:00
|
|
|
coreCode := make(map[core.Hash][]byte)
|
|
|
|
for k, v := range codeUpdates {
|
|
|
|
coreCode[core.Hash(k)] = v
|
|
|
|
}
|
2021-09-03 22:20:49 +00:00
|
|
|
|
2021-09-01 20:34:03 +00:00
|
|
|
for _, fni := range fnList {
|
2021-09-20 15:44:07 +00:00
|
|
|
if fn, ok := fni.(func(core.Hash, core.Hash, map[core.Hash]struct{}, map[core.Hash][]byte, map[core.Hash]map[core.Hash][]byte, map[core.Hash][]byte)); ok {
|
|
|
|
fn(core.Hash(blockRoot), core.Hash(parentRoot), coreDestructs, coreAccounts, coreStorage, coreCode)
|
2021-09-01 20:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-12 19:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 15:44:07 +00:00
|
|
|
func pluginStateUpdate(blockRoot, parentRoot common.Hash, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) {
|
2021-07-12 19:45:42 +00:00
|
|
|
if plugins.DefaultPluginLoader == nil {
|
|
|
|
log.Warn("Attempting StateUpdate, but default PluginLoader has not been initialized")
|
2021-09-01 20:34:03 +00:00
|
|
|
return
|
|
|
|
}
|
2021-09-20 15:44:07 +00:00
|
|
|
PluginStateUpdate(plugins.DefaultPluginLoader, blockRoot, parentRoot, destructs, accounts, storage, codeUpdates)
|
2021-07-12 19:45:42 +00:00
|
|
|
}
|