Skip to content

Commit 49f6a00

Browse files
authored
update l2 bridge config whenever l1 config is updated (#81)
* update l2 bridge config whenever l1 config is updated * format * decrease trusting period
1 parent 95e8103 commit 49f6a00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1011
-85
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ This repository contains the Go implementation of OPinit bots.
1313

1414
Before running OPinit bots, make sure you have the following prerequisites installed:
1515

16-
- Go 1.22.2+
16+
- Go 1.22.5+
1717

1818
To ensure compatibility with the node version, check the following versions:
1919

2020
| L1 Node | MiniMove | MiniWasm | MiniEVM | Celestia-appd |
2121
| ------- | -------- | -------- | ------- | ------------- |
22-
| v0.6.4+ | v0.6.5+ | v0.6.5+ | v0.6.7+ | v3.2.0+ |
22+
| v0.7.2+ | v0.7.0+ | v0.7.0+ | v0.7.2+ | v3.3.2+ |
2323

2424
### Build and Configure
2525

@@ -94,6 +94,7 @@ Executor node types:
9494
- host
9595
- child
9696
- batch
97+
- da
9798

9899
Challenger node types:
99100
- host

challenger/challenger.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ func (c *Challenger) Initialize(ctx types.Context) error {
103103
zap.Duration("submission_interval", bridgeInfo.BridgeConfig.SubmissionInterval),
104104
)
105105

106+
childBridgeInfo.BridgeConfig = bridgeInfo.BridgeConfig
107+
106108
l1StartHeight, l2StartHeight, startOutputIndex, err := c.getNodeStartHeights(ctx, bridgeInfo.BridgeId)
107109
if err != nil {
108110
return err
@@ -117,7 +119,7 @@ func (c *Challenger) Initialize(ctx types.Context) error {
117119
initialBlockTime = hostInitialBlockTime
118120
}
119121

120-
childInitialBlockTime, err := c.child.Initialize(ctx, l2StartHeight-1, startOutputIndex, c.host, *bridgeInfo, c)
122+
childInitialBlockTime, err := c.child.Initialize(ctx, l2StartHeight-1, startOutputIndex, c.host, childBridgeInfo, c)
121123
if err != nil {
122124
return err
123125
}

challenger/child/child.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (ch *Child) Initialize(
6363
processedHeight int64,
6464
startOutputIndex uint64,
6565
host hostNode,
66-
bridgeInfo ophosttypes.QueryBridgeResponse,
66+
bridgeInfo opchildtypes.BridgeInfo,
6767
challenger challenger,
6868
) (time.Time, error) {
6969
_, err := ch.BaseChild.Initialize(

challenger/child/deposit_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
"time"
88

9-
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
9+
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
1010
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
1111
"github.com/initia-labs/opinit-bots/db"
1212
"github.com/initia-labs/opinit-bots/node"
@@ -24,7 +24,7 @@ func TestFinalizeDepositHandler(t *testing.T) {
2424
require.NoError(t, err)
2525

2626
childNode := node.NewTestNode(nodetypes.NodeConfig{}, db.WithPrefix([]byte("test_child")), nil, nil, nil, nil)
27-
bridgeInfo := ophosttypes.QueryBridgeResponse{
27+
bridgeInfo := opchildtypes.BridgeInfo{
2828
BridgeId: 1,
2929
}
3030

challenger/child/handler_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
9+
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
910
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
1011
eventhandler "github.com/initia-labs/opinit-bots/challenger/eventhandler"
1112
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
@@ -44,7 +45,7 @@ func TestBeginBlockHandler(t *testing.T) {
4445
})
4546

4647
ch := Child{
47-
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, ophosttypes.QueryBridgeResponse{
48+
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, opchildtypes.BridgeInfo{
4849
BridgeId: 1,
4950
}, nil, nodetypes.NodeConfig{}),
5051
host: mockHost,
@@ -375,7 +376,7 @@ func TestEndBlockHandler(t *testing.T) {
375376
})
376377
require.NoError(t, err)
377378
ch := Child{
378-
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, ophosttypes.QueryBridgeResponse{}, nil, nodetypes.NodeConfig{}),
379+
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, opchildtypes.BridgeInfo{}, nil, nodetypes.NodeConfig{}),
379380
host: tc.host,
380381
challenger: tc.challenger,
381382
stage: childdb.NewStage(),

challenger/child/oracle_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
"time"
77

8-
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
8+
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
99
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
1010
"github.com/initia-labs/opinit-bots/db"
1111
"github.com/initia-labs/opinit-bots/node"
@@ -21,7 +21,7 @@ func TestOracleTxHandler(t *testing.T) {
2121
db, err := db.NewMemDB()
2222
require.NoError(t, err)
2323
childNode := node.NewTestNode(nodetypes.NodeConfig{}, db.WithPrefix([]byte("test_child")), nil, nil, nil, nil)
24-
bridgeInfo := ophosttypes.QueryBridgeResponse{
24+
bridgeInfo := opchildtypes.BridgeInfo{
2525
BridgeId: 1,
2626
}
2727

challenger/child/withdraw_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
9+
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
910
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
1011
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
1112
"github.com/initia-labs/opinit-bots/db"
@@ -22,7 +23,7 @@ import (
2223
)
2324

2425
func TestInitiateWithdrawalHandler(t *testing.T) {
25-
bridgeInfo := ophosttypes.QueryBridgeResponse{
26+
bridgeInfo := opchildtypes.BridgeInfo{
2627
BridgeId: 1,
2728
}
2829

@@ -160,7 +161,7 @@ func TestInitiateWithdrawalHandler(t *testing.T) {
160161
}
161162

162163
func TestPrepareTree(t *testing.T) {
163-
bridgeInfo := ophosttypes.QueryBridgeResponse{
164+
bridgeInfo := opchildtypes.BridgeInfo{
164165
BridgeId: 1,
165166
}
166167

@@ -304,15 +305,15 @@ func TestPrepareTree(t *testing.T) {
304305
func TestPrepareOutput(t *testing.T) {
305306
cases := []struct {
306307
name string
307-
bridgeInfo ophosttypes.QueryBridgeResponse
308+
bridgeInfo opchildtypes.BridgeInfo
308309
hostOutputs map[uint64]ophosttypes.Output
309310
lastWorkingTree merkletypes.TreeInfo
310311
expected func() (lastOutputTime time.Time, nextOutputTime time.Time, finalizingBlockHeight int64)
311312
err bool
312313
}{
313314
{
314315
name: "no output, index 1",
315-
bridgeInfo: ophosttypes.QueryBridgeResponse{
316+
bridgeInfo: opchildtypes.BridgeInfo{
316317
BridgeId: 1,
317318
BridgeConfig: ophosttypes.BridgeConfig{
318319
SubmissionInterval: 100,
@@ -334,7 +335,7 @@ func TestPrepareOutput(t *testing.T) {
334335
},
335336
{
336337
name: "no output, index 3", // chain rolled back
337-
bridgeInfo: ophosttypes.QueryBridgeResponse{
338+
bridgeInfo: opchildtypes.BridgeInfo{
338339
BridgeId: 1,
339340
BridgeConfig: ophosttypes.BridgeConfig{
340341
SubmissionInterval: 100,
@@ -356,7 +357,7 @@ func TestPrepareOutput(t *testing.T) {
356357
},
357358
{
358359
name: "outputs {1}, index 1", // sync
359-
bridgeInfo: ophosttypes.QueryBridgeResponse{
360+
bridgeInfo: opchildtypes.BridgeInfo{
360361
BridgeId: 1,
361362
BridgeConfig: ophosttypes.BridgeConfig{
362363
SubmissionInterval: 100,
@@ -383,7 +384,7 @@ func TestPrepareOutput(t *testing.T) {
383384
},
384385
{
385386
name: "outputs {1}, index 2",
386-
bridgeInfo: ophosttypes.QueryBridgeResponse{
387+
bridgeInfo: opchildtypes.BridgeInfo{
387388
BridgeId: 1,
388389
BridgeConfig: ophosttypes.BridgeConfig{
389390
SubmissionInterval: 300,
@@ -452,7 +453,7 @@ func TestPrepareOutput(t *testing.T) {
452453
}
453454

454455
func TestHandleTree(t *testing.T) {
455-
bridgeInfo := ophosttypes.QueryBridgeResponse{
456+
bridgeInfo := opchildtypes.BridgeInfo{
456457
BridgeId: 1,
457458
BridgeConfig: ophosttypes.BridgeConfig{
458459
SubmissionInterval: 300,
@@ -683,7 +684,7 @@ func TestHandleOutput(t *testing.T) {
683684
blockId []byte
684685
outputIndex uint64
685686
storageRoot []byte
686-
bridgeInfo ophosttypes.QueryBridgeResponse
687+
bridgeInfo opchildtypes.BridgeInfo
687688
host *mockHost
688689
expected []challengertypes.ChallengeEvent
689690
err bool
@@ -696,7 +697,7 @@ func TestHandleOutput(t *testing.T) {
696697
blockId: []byte("latestBlockHashlatestBlockHashla"),
697698
outputIndex: 1,
698699
storageRoot: []byte("storageRootstorageRootstorageRoo"),
699-
bridgeInfo: ophosttypes.QueryBridgeResponse{BridgeId: 1},
700+
bridgeInfo: opchildtypes.BridgeInfo{BridgeId: 1},
700701
host: NewMockHost(nil, 5),
701702
expected: []challengertypes.ChallengeEvent{
702703
&challengertypes.Output{

challenger/host/bridge_info.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package host
2+
3+
import (
4+
"github.com/pkg/errors"
5+
"go.uber.org/zap"
6+
7+
hostprovider "github.com/initia-labs/opinit-bots/provider/host"
8+
9+
nodetypes "github.com/initia-labs/opinit-bots/node/types"
10+
"github.com/initia-labs/opinit-bots/types"
11+
)
12+
13+
func (h *Host) updateProposerHandler(ctx types.Context, args nodetypes.EventHandlerArgs) error {
14+
bridgeId, proposer, finalizedOutputIndex, finalizedL2BlockNumber, err := hostprovider.ParseMsgUpdateProposer(args.EventAttributes)
15+
if err != nil {
16+
return errors.Wrap(err, "failed to parse update proposer event")
17+
}
18+
if bridgeId != h.BridgeId() {
19+
return nil
20+
}
21+
22+
ctx.Logger().Warn("update proposer",
23+
zap.Uint64("bridge_id", bridgeId),
24+
zap.String("proposer", proposer),
25+
zap.Uint64("finalized_output_index", finalizedOutputIndex),
26+
zap.Uint64("finalized_l2_block_number", finalizedL2BlockNumber),
27+
)
28+
29+
h.UpdateProposer(proposer)
30+
return nil
31+
}
32+
33+
func (h *Host) updateChallengerHandler(ctx types.Context, args nodetypes.EventHandlerArgs) error {
34+
bridgeId, challenger, finalizedOutputIndex, finalizedL2BlockNumber, err := hostprovider.ParseMsgUpdateChallenger(args.EventAttributes)
35+
if err != nil {
36+
return errors.Wrap(err, "failed to parse update challenger event")
37+
}
38+
if bridgeId != h.BridgeId() {
39+
return nil
40+
}
41+
42+
ctx.Logger().Info("update challenger",
43+
zap.Uint64("bridge_id", bridgeId),
44+
zap.String("challenger", challenger),
45+
zap.Uint64("finalized_output_index", finalizedOutputIndex),
46+
zap.Uint64("finalized_l2_block_number", finalizedL2BlockNumber),
47+
)
48+
49+
h.UpdateChallenger(challenger)
50+
return nil
51+
}

0 commit comments

Comments
 (0)