Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
type buildTemplateModule struct {}

// GetAPIs fires as the node is registering its APIs. It should return a list of rpc.API objects so that plugins can register new RPC methods. This brings the plugin module into compliance with the apis.GetAPIs interface.
func (*buildTemplateModule) GetAPIs(stack *node.Node, backend types.Backend) []rpc.API {
func (*buildTemplateModule) GetAPIs(stack *node.Node, backend types.Backend, cfg any) []rpc.API {
return nil
}

Expand All @@ -51,7 +51,7 @@ func (*buildTemplateModule) SetTrieFlushIntervalClone(flushInterval time.Duratio
}

// InitializeNode fires as the node starts. This brings the plugin module into compliance with the initialize.Initializer interface.
func (*buildTemplateModule) InitializeNode(stack *node.Node, backend types.Backend) {
func (*buildTemplateModule) InitializeNode(stack *node.Node, backend types.Backend, cfg any) {
log.Info("build template plugin initailized")
}

Expand Down
2 changes: 1 addition & 1 deletion hooks/apis/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type GetAPIs interface {
GetAPIs(*node.Node, types.Backend) []rpc.API
GetAPIs(*node.Node, types.Backend, any) []rpc.API
}

func init() {
Expand Down
47 changes: 4 additions & 43 deletions hooks/initialize/patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
var initializePatchsets = []xplugeth.Patchset {
xplugeth.Patchset{
Remote: "github.com/openrelayxyz/xplugeth-patches",
Ref: "hooks_foundation_init_v1.15.0_0",
// https://github.com/openrelayxyz/xplugeth-patches/commit/be5ea0b65724131135ffe17971a1fdea2e41359d
Ref: "hooks_foundation_init_v1.16.5_2",
// https://github.com/openrelayxyz/xplugeth-patches/commit/2cd24b3eb2890e62799d6a45d1a36f56060ad5aa
Tests: []xplugeth.Test{
{
Package: "./cmd/geth",
Expand All @@ -20,8 +20,8 @@ var initializePatchsets = []xplugeth.Patchset {
},
xplugeth.Patchset{
Remote: "github.com/openrelayxyz/xplugeth-patches",
Ref: "hooks_foundation_init_v1.14.12_4",
// https://github.com/openrelayxyz/xplugeth-patches/commit/51cc5dd64eb7fbeb72d47613da50778b52601ef4
Ref: "hooks_etc_init_v1.12.20_9",
// https://github.com/openrelayxyz/xplugeth-patches/commit/bea9c77474bdb2958ace2e4f8ee7d862ac691248
Tests: []xplugeth.Test{
{
Package: "./cmd/geth",
Expand All @@ -31,43 +31,4 @@ var initializePatchsets = []xplugeth.Patchset {
},
},
},
xplugeth.Patchset{
Remote: "github.com/openrelayxyz/xplugeth-patches",
Ref: "hooks_etc_init_v1.12.20_8",
// https://github.com/openrelayxyz/xplugeth-patches/commit/2c9034476ba9d8ea5c0df4e24f551d862cd69798
Tests: []xplugeth.Test{
{
Package: "./cmd/geth",
TestNames: []string{
"TestGethPkgInjections",
},
},
},
},
xplugeth.Patchset{
Remote: "github.com/openrelayxyz/xplugeth-patches",
Ref: "hooks_bor_init_v1.5.3_2",
// https://github.com/openrelayxyz/xplugeth-patches/commit/b7184a28f74cfb56402cbf703a8246ea8831742a
Tests: []xplugeth.Test{
{
Package: "./internal/cli/server",
TestNames: []string{
"TestServerPkgInjections",
},
},
},
},
xplugeth.Patchset{
Remote: "github.com/openrelayxyz/xplugeth-patches",
Ref: "hooks_bor_init_v2.0.3_0",
// https://github.com/openrelayxyz/xplugeth-patches/commit/c4704227fb138bc1194b98e8282d56fed128016c
Tests: []xplugeth.Test{
{
Package: "./internal/cli/server",
TestNames: []string{
"TestServerPkgInjections",
},
},
},
},
}
2 changes: 1 addition & 1 deletion hooks/initialize/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Blockchain interface {
}

type Initializer interface {
InitializeNode(*node.Node, types.Backend)
InitializeNode(*node.Node, types.Backend, any)
}

func init() {
Expand Down
25 changes: 10 additions & 15 deletions plugins/blockupdates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var (
suCh chan *stateUpdateWithRoot
)


// stateUpdate will be used to track state updates
type stateUpdate struct {
Destructs map[common.Hash]struct{}
Expand Down Expand Up @@ -73,7 +72,6 @@ type storedStateUpdate struct {
Code []kvpair
}


// MarshalJSON represents the stateUpdate as JSON for RPC calls
func (su *stateUpdate) MarshalJSON() ([]byte, error) {
result := make(map[string]interface{})
Expand Down Expand Up @@ -191,7 +189,7 @@ func init() {
// InitializeNode is invoked by the plugin loader when the node and Backend are
// ready. We will track the backend to provide access to blocks and other
// useful information.
func (bu *blockUpdatesModule) InitializeNode(stack *node.Node, b types.Backend) {
func (bu *blockUpdatesModule) InitializeNode(stack *node.Node, b types.Backend, c any) {
bu.backend = b
sessionBackend = b
blockEvents = &event.Feed{}
Expand All @@ -215,7 +213,6 @@ func (bu *blockUpdatesModule) InitializeNode(stack *node.Node, b types.Backend)
log.Info("block updater plugin initialized")
}


// // StateUpdate gives us updates about state changes made in each block. We
// // cache them for short term use, and write them to disk for the longer term.
func (bu *blockUpdatesModule) StateUpdate(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) {
Expand Down Expand Up @@ -259,6 +256,7 @@ func (bu *blockUpdatesModule) ModifyAncients(number uint64, header *gtypes.Heade
func (*blockUpdatesModule) NewHead(block *gtypes.Block, hash common.Hash, logs []*gtypes.Log, td *big.Int) {
newHead(*block, hash, td)
}

func newHead(block gtypes.Block, hash common.Hash, td *big.Int) {
if recentEmits.Contains(hash) {
log.Debug("Skipping recently emitted block")
Expand Down Expand Up @@ -318,7 +316,6 @@ func (bu *blockUpdatesModule) Reorg(common common.Hash, oldChain []common.Hash,
}
}


// blockUpdates is a service that lets clients query for block updates for a
// given block by hash or number, or subscribe to new block upates.
func (b *blockUpdatesModule) BlockUpdatesByNumber(number int64) (*gtypes.Block, *big.Int, gtypes.Receipts, map[common.Hash]struct{}, map[common.Hash][]byte, map[common.Hash]map[common.Hash][]byte, map[common.Hash][]byte, error) {
Expand Down Expand Up @@ -391,7 +388,6 @@ func (b *blockUpdatesAPI) TestBlockUpdates(ctx context.Context) string {
return "calling back from blockUpdates plugin"
}


// BlockUpdates allows clients to subscribe to notifications of new blocks
// along with receipts and state updates.
func (b *blockUpdatesAPI) BlockUpdates(ctx context.Context) (<-chan map[string]interface{}, error) {
Expand All @@ -416,17 +412,16 @@ func (b *blockUpdatesAPI) BlockUpdates(ctx context.Context) (<-chan map[string]i
return ch, nil
}


// GetAPIs exposes the BlockUpdates service under the cardinal namespace.
func (*blockUpdatesModule) GetAPIs(stack *node.Node, backend types.Backend) []rpc.API {
func (*blockUpdatesModule) GetAPIs(stack *node.Node, backend types.Backend, chainConfig any) []rpc.API {
return []rpc.API{
{
Namespace: "plugeth",
Version: "1.0",
Service: &blockUpdatesAPI{backend},
Public: true,
},
}
{
Namespace: "plugeth",
Version: "1.0",
Service: &blockUpdatesAPI{backend},
Public: true,
},
}
}

func (b *blockUpdatesAPI) BlockUpdatesAPITest(context.Context) string {
Expand Down
4 changes: 2 additions & 2 deletions plugins/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ExampleConfig struct {
var cfg *ExampleConfig


func (*exampleModule) InitializeNode(*node.Node, types.Backend) {
func (*exampleModule) InitializeNode(*node.Node, types.Backend, any) {
log.Info("Example module initialized")

if *exampleBoolFlag {
Expand All @@ -66,7 +66,7 @@ func (*exampleModule) Shutdown() {
log.Info("Byeee!")
}

func (*exampleModule) GetAPIs(*node.Node, types.Backend) []rpc.API {
func (*exampleModule) GetAPIs(*node.Node, types.Backend, any) []rpc.API {
log.Info("Registering plugin APIs")
return []rpc.API{
{
Expand Down
93 changes: 93 additions & 0 deletions plugins/forkready/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package forkready

import (
"reflect"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc"

"github.com/openrelayxyz/xplugeth"
"github.com/openrelayxyz/xplugeth/hooks/apis"
"github.com/openrelayxyz/xplugeth/hooks/initialize"
"github.com/openrelayxyz/xplugeth/types"
)

type forkReadyModule struct {
}

func init() {
xplugeth.RegisterModule[forkReadyModule]("forkReady")
}

func (r *forkReadyModule) InitializeNode(stack *node.Node, backend types.Backend, cfg any) {
log.Info("forkReady module initialized")
}

func (r *forkReadyModule) GetAPIs(s *node.Node, b types.Backend, c any) []rpc.API {
return []rpc.API{
{
Namespace: "cardinal",
Service: &forkReadyAPI{
stack: s,
chainConfig: c,
},
},
}
}

type forkReadyAPI struct{
stack *node.Node
chainConfig any
}

type psudoConfig struct {
OsakaTime *uint64
}

func (r *forkReadyAPI) ForkReady(forkName string) int {
result := -1
client := r.stack.Attach()
if client == nil {
log.Error("error acquiring client, ForkReady plugin")
return result
}
switch forkName {
case "osaka":
var latestBlock map[string]interface{}
if err := client.Call(&latestBlock, "eth_getBlockByNumber", "latest", false); err != nil {
log.Error("error returned from client call, forkReady plugin", "err", err)
return result
}
blockTime, err := hexutil.DecodeUint64(latestBlock["timestamp"].(string))
if err != nil {
log.Error("error decoding latest block timestamp, forkReady plugin", "err", err)
return result
}
metaCfg := reflect.ValueOf(r.chainConfig)
if metaCfg.Kind() == reflect.Ptr {
metaCfg = metaCfg.Elem()
}
val := metaCfg.FieldByName("OsakaTime")
if val.IsValid() {
if !val.IsNil() {
oTime := *val.Interface().(*uint64)
// this may need to be complexified if / when other supported chains add osakaTime to their chain configs
if blockTime >= oTime {
result = 2
} else {
result = 1
}
} else {
result = 0
}
}
}
return result
}

var (
_ apis.GetAPIs = (*forkReadyModule)(nil)
_ initialize.Initializer = (*forkReadyModule)(nil)
)
2 changes: 1 addition & 1 deletion plugins/healthcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
xplugeth.RegisterModule[healthCheckModule]("healthcheck")
}

func (h *healthCheckModule) InitializeNode(s *node.Node, b types.Backend) {
func (h *healthCheckModule) InitializeNode(s *node.Node, b types.Backend, c any) {
h.client = s.Attach()

h.tolerance = *hcTolerance
Expand Down
2 changes: 1 addition & 1 deletion plugins/merge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
xplugeth.RegisterModule[mergePlugin]("mergePlugin")
}

func (*mergePlugin) InitializeNode(s *node.Node, b types.Backend) {
func (*mergePlugin) InitializeNode(s *node.Node, b types.Backend, c any) {
stack = *s
backend = b

Expand Down
2 changes: 1 addition & 1 deletion plugins/peereval/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func init() {
xplugeth.RegisterFlags(flags)
}

func (p *peerEvalModule) InitializeNode(s *node.Node, b types.Backend) {
func (p *peerEvalModule) InitializeNode(s *node.Node, b types.Backend, c any) {
client = s.Attach()

p.peerMetricsMap = make(map[string]*PeerMetrics)
Expand Down
2 changes: 1 addition & 1 deletion plugins/peermanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {
xplugeth.RegisterModule[peerManagerModule]("peerManagerModule")
}

func (p *peerManagerModule) InitializeNode(s *node.Node, b types.Backend) {
func (p *peerManagerModule) InitializeNode(s *node.Node, b types.Backend, c any) {

sessionPeerService = &PeerManager{
client: s.Attach(),
Expand Down
4 changes: 2 additions & 2 deletions plugins/producer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func strPtr(x string) *string {
return &x
}

func (*cardinalProducerModule) InitializeNode(s *node.Node, b types.Backend) {
func (*cardinalProducerModule) InitializeNode(s *node.Node, b types.Backend, c any) {

if present := xplugeth.HasModule("blockUpdatesModule"); !present {
panic("blockUpdates plugin not detected from cardinal plugin")
Expand Down Expand Up @@ -561,7 +561,7 @@ func (api *cardinalAPI) ReproduceBlocks(start rpc.BlockNumber, end *rpc.BlockNum
return true, nil
}

func (c *cardinalProducerModule) GetAPIs(stack *node.Node, backend types.Backend) []rpc.API {
func (c *cardinalProducerModule) GetAPIs(stack *node.Node, backend types.Backend, chainConfig any) []rpc.API {
var v func(int64) (*gtypes.Block, *big.Int, gtypes.Receipts, map[common.Hash]struct{}, map[common.Hash][]byte, map[common.Hash]map[common.Hash][]byte, map[common.Hash][]byte, error)
for _, extern := range xplugeth.GetModules[blockupdates.InternalBlockUpdates]() {
v = extern.BlockUpdatesByNumber
Expand Down