forked from cerc-io/plugeth
Changes made to support unity across all plugeth projects with resepct to consensus engine.
This commit is contained in:
parent
477985fdcd
commit
bb43b2cbc4
@ -171,8 +171,8 @@ type Config struct {
|
||||
func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
|
||||
// If proof-of-authority is requested, set it up
|
||||
//begin PluGeth code injection
|
||||
if engine := pluginGetEngine(); engine != nil {
|
||||
log.Error("returning plugin consensus engine")
|
||||
if engine := pluginGetEngine(config, db); engine != nil {
|
||||
log.Info("returning plugin consensus engine")
|
||||
return engine, nil
|
||||
}
|
||||
//end PluGeth code injection
|
||||
|
@ -3,29 +3,30 @@ 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/params"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
// "github.com/ethereum/go-ethereum/ethdb"
|
||||
// "github.com/ethereum/go-ethereum/node"
|
||||
|
||||
"github.com/ethereum/go-ethereum/plugins/wrappers/backendwrapper"
|
||||
wengine "github.com/ethereum/go-ethereum/plugins/wrappers/engine"
|
||||
|
||||
"github.com/openrelayxyz/plugeth-utils/restricted"
|
||||
pparams "github.com/openrelayxyz/plugeth-utils/restricted/params"
|
||||
pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func PluginGetEngine(pl *plugins.PluginLoader) consensus.Engine {
|
||||
func PluginGetEngine(pl *plugins.PluginLoader, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
|
||||
fnList := pl.Lookup("CreateEngine", func(item interface{}) bool {
|
||||
_, ok := item.(func() pconsensus.Engine)
|
||||
_, ok := item.(func(*pparams.ChainConfig, restricted.Database) pconsensus.Engine)
|
||||
return ok
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
if fn, ok := fni.(func() pconsensus.Engine); ok {
|
||||
if engine := fn(); engine != nil {
|
||||
if fn, ok := fni.(func(*pparams.ChainConfig, restricted.Database) pconsensus.Engine); ok {
|
||||
clonedConfig := backendwrapper.CloneChainConfig(chainConfig)
|
||||
wrappedDb := backendwrapper.NewDb(db)
|
||||
if engine := fn(clonedConfig, wrappedDb); engine != nil {
|
||||
wrappedEngine := wengine.NewWrappedEngine(engine)
|
||||
return wrappedEngine
|
||||
}
|
||||
@ -35,10 +36,10 @@ func PluginGetEngine(pl *plugins.PluginLoader) consensus.Engine {
|
||||
return nil
|
||||
}
|
||||
|
||||
func pluginGetEngine() consensus.Engine {
|
||||
func pluginGetEngine(chainConfig *params.ChainConfig, 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)
|
||||
return PluginGetEngine(plugins.DefaultPluginLoader, chainConfig, db)
|
||||
}
|
@ -1 +0,0 @@
|
||||
map[LiveCaptureEnd:{} LiveCaptureStart:{} LiveCaptureState:{} LivePostProcessBlock:{} PostProcessBlock:{}]
|
@ -1,70 +0,0 @@
|
||||
[ -f "passwordfile" ] && rm -f passwordfile
|
||||
[ -d "00/" ] && rm -rf 00/
|
||||
[ -d "test00/" ] && rm -rf test00/
|
||||
[ -d "01/" ] && rm -rf 01/
|
||||
[ -d "test01/" ] && rm -rf test01/
|
||||
[ -d "02/" ] && rm -rf 02/
|
||||
[ -d "test02/" ] && rm -rf test02/
|
||||
|
||||
mkdir -p test00 test01 test02 00/keystore 01/keystore 02/keystore 00/geth 01/geth 02/geth 00/plugins 01/plugins 02/plugins
|
||||
|
||||
|
||||
cp ../engine.go test00/
|
||||
cp ../engine.go ../main.go ../hooks.go ../tracer.go ../live_tracer.go test01/
|
||||
cp ../engine.go ../shutdown.go test02/
|
||||
cd test00/
|
||||
go build -buildmode=plugin -o ../00/plugins
|
||||
cd ../
|
||||
cd test01/
|
||||
go build -buildmode=plugin -o ../01/plugins
|
||||
cd ../
|
||||
cd test02/
|
||||
go build -buildmode=plugin -o ../02/plugins
|
||||
cd ../
|
||||
|
||||
cp UTC--2021-03-02T16-47-49.510918858Z--f2c207111cb6ef761e439e56b25c7c99ac026a01 00/keystore
|
||||
cp UTC--2021-03-02T16-47-39.492920333Z--4204477bf7fce868e761caaba991ffc607717dbf 01/keystore
|
||||
cp UTC--2021-03-02T16-47-59.816632526Z--2cb2e3bdb066a83a7f1191eef1697da51793f631 02/keystore
|
||||
|
||||
cp nodekey00 00/geth/nodekey
|
||||
cp nodekey01 01/geth/nodekey
|
||||
cp nodekey02 02/geth/nodekey
|
||||
|
||||
echo -n "supersecretpassword" > passwordfile
|
||||
|
||||
$GETH init --datadir=./00 genesis.json
|
||||
$GETH init --datadir=./01 genesis.json
|
||||
$GETH init --datadir=./02 genesis.json
|
||||
|
||||
# miner node
|
||||
$GETH --cache.preimages --config config00.toml --authrpc.port 8552 --port 64480 --verbosity=0 --nodiscover --networkid=6448 --datadir=./00/ --mine --miner.etherbase f2c207111cb6ef761e439e56b25c7c99ac026a01 --unlock f2c207111cb6ef761e439e56b25c7c99ac026a01 --http --http.api eth,debug,net --http.port 9545 --password passwordfile --allow-insecure-unlock &
|
||||
pid0=$!
|
||||
|
||||
sleep 1
|
||||
# passive node
|
||||
$GETH --cache.preimages --config config01.toml --authrpc.port 8553 --port 64481 --verbosity=3 --syncmode=full --nodiscover --networkid=6448 --datadir=./01/ --unlock 4204477bf7fce868e761caaba991ffc607717dbf --miner.etherbase 4204477bf7fce868e761caaba991ffc607717dbf --password passwordfile --ws --ws.port 8546 --ws.api eth,admin --http --http.api eth,debug,net --http.port 9546 --allow-insecure-unlock &
|
||||
|
||||
sleep 1
|
||||
|
||||
# shutdown node
|
||||
$GETH --config config02.toml --authrpc.port 8556 --port 64484 --verbosity=0 --syncmode=full --nodiscover --networkid=6448 --datadir=./02/ --unlock 2cb2e3bdb066a83a7f1191eef1697da51793f631 --miner.etherbase 2cb2e3bdb066a83a7f1191eef1697da51793f631 --password passwordfile --ws --ws.port 8548 --ws.api eth,admin --http --http.api eth,debug,net --http.port 9547 --allow-insecure-unlock &
|
||||
pid1=$!
|
||||
|
||||
sleep 5
|
||||
|
||||
if ps -p $pid1 > /dev/null; then
|
||||
kill $pid1
|
||||
fi
|
||||
|
||||
sleep 255
|
||||
|
||||
if ps -p $pid0 > /dev/null; then
|
||||
kill $pid0
|
||||
fi
|
||||
|
||||
wait
|
||||
|
||||
rm -f passwordfile
|
||||
rm -rf 00/ 01/ 02/ test00/ test01/ test02/
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
gparams "github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
@ -463,6 +464,28 @@ func (b *Backend) ChainConfig() *params.ChainConfig {
|
||||
return b.chainConfig
|
||||
}
|
||||
|
||||
func CloneChainConfig(cf *gparams.ChainConfig) *params.ChainConfig {
|
||||
result := ¶ms.ChainConfig{}
|
||||
nval := reflect.ValueOf(result)
|
||||
ntype := nval.Elem().Type()
|
||||
lval := reflect.ValueOf(cf)
|
||||
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 result
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -11,7 +11,7 @@ type dbWrapper struct {
|
||||
db ethdb.Database
|
||||
}
|
||||
|
||||
func NewDB(d ethdb.Database) restricted.Database {
|
||||
func NewDb(d ethdb.Database) restricted.Database {
|
||||
return &dbWrapper{d}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user