Skip to content

Commit 020b4ad

Browse files
generic chainconfig forkready logic
1 parent d9efb58 commit 020b4ad

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

plugins/forkready/main.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/ethereum/go-ethereum/common/hexutil"
77
"github.com/ethereum/go-ethereum/log"
88
"github.com/ethereum/go-ethereum/node"
9-
"github.com/ethereum/go-ethereum/params"
109
"github.com/ethereum/go-ethereum/rpc"
1110

1211
"github.com/openrelayxyz/xplugeth"
@@ -15,8 +14,6 @@ import (
1514
"github.com/openrelayxyz/xplugeth/types"
1615
)
1716

18-
var chainConfig any
19-
2017
type forkReadyModule struct {
2118
}
2219

@@ -25,23 +22,28 @@ func init() {
2522
}
2623

2724
func (r *forkReadyModule) InitializeNode(stack *node.Node, backend types.Backend, cfg any) {
28-
chainConfig = cfg
2925
log.Info("forkReady module initialized")
3026
}
3127

32-
func (r *forkReadyModule) GetAPIs(s *node.Node, b types.Backend) []rpc.API {
28+
func (r *forkReadyModule) GetAPIs(s *node.Node, b types.Backend, c any) []rpc.API {
3329
return []rpc.API{
3430
{
3531
Namespace: "cardinal",
3632
Service: &forkReadyAPI{
3733
stack: s,
34+
chainConfig: c,
3835
},
3936
},
4037
}
4138
}
4239

4340
type forkReadyAPI struct{
4441
stack *node.Node
42+
chainConfig any
43+
}
44+
45+
type psudoConfig struct {
46+
OsakaTime *uint64
4547
}
4648

4749
func (r *forkReadyAPI) ForkReady(forkName string) int {
@@ -63,22 +65,25 @@ func (r *forkReadyAPI) ForkReady(forkName string) int {
6365
log.Error("error decoding latest block timestamp, forkReady plugin", "err", err)
6466
return result
6567
}
66-
metaCfg := reflect.ValueOf(chainConfig).Type().Elem()
67-
if _, ok := metaCfg.FieldByName("OsakaTime"); ok {
68-
ptr := chainConfig.(*params.ChainConfig)
69-
cfg := *ptr
70-
if oTime := cfg.OsakaTime; oTime != nil {
71-
if blockTime >= *oTime {
68+
metaCfg := reflect.ValueOf(r.chainConfig)
69+
if metaCfg.Kind() == reflect.Ptr {
70+
metaCfg = metaCfg.Elem()
71+
}
72+
val := metaCfg.FieldByName("OsakaTime")
73+
if val.IsValid() {
74+
if !val.IsNil() {
75+
oTime := *val.Interface().(*uint64)
76+
// this may need to be complexified if / when other supported chains add osakaTime to their chain configs
77+
if blockTime >= oTime {
7278
result = 2
7379
} else {
7480
result = 1
75-
}
81+
}
7682
} else {
7783
result = 0
7884
}
7985
}
8086
}
81-
8287
return result
8388
}
8489

0 commit comments

Comments
 (0)