Skip to content

Commit

Permalink
update l2 bridge config whenever l1 config is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha committed Feb 19, 2025
1 parent b815d14 commit 919d32b
Show file tree
Hide file tree
Showing 43 changed files with 1,007 additions and 83 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ This repository contains the Go implementation of OPinit bots.

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

- Go 1.22.2+
- Go 1.22.5+

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

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

### Build and Configure

Expand Down Expand Up @@ -94,6 +94,7 @@ Executor node types:
- host
- child
- batch
- da

Challenger node types:
- host
Expand Down
4 changes: 3 additions & 1 deletion challenger/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (c *Challenger) Initialize(ctx types.Context) error {
zap.Duration("submission_interval", bridgeInfo.BridgeConfig.SubmissionInterval),
)

childBridgeInfo.BridgeConfig = bridgeInfo.BridgeConfig

l1StartHeight, l2StartHeight, startOutputIndex, err := c.getNodeStartHeights(ctx, bridgeInfo.BridgeId)
if err != nil {
return err
Expand All @@ -111,7 +113,7 @@ func (c *Challenger) Initialize(ctx types.Context) error {
initialBlockTime = hostInitialBlockTime
}

childInitialBlockTime, err := c.child.Initialize(ctx, l2StartHeight-1, startOutputIndex, c.host, *bridgeInfo, c)
childInitialBlockTime, err := c.child.Initialize(ctx, l2StartHeight-1, startOutputIndex, c.host, childBridgeInfo, c)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion challenger/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (ch *Child) Initialize(
processedHeight int64,
startOutputIndex uint64,
host hostNode,
bridgeInfo ophosttypes.QueryBridgeResponse,
bridgeInfo opchildtypes.BridgeInfo,
challenger challenger,
) (time.Time, error) {
_, err := ch.BaseChild.Initialize(
Expand Down
4 changes: 2 additions & 2 deletions challenger/child/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

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

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

Expand Down
5 changes: 3 additions & 2 deletions challenger/child/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

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

ch := Child{
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, ophosttypes.QueryBridgeResponse{
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, opchildtypes.BridgeInfo{
BridgeId: 1,
}, nil, nodetypes.NodeConfig{}),
host: mockHost,
Expand Down Expand Up @@ -375,7 +376,7 @@ func TestEndBlockHandler(t *testing.T) {
})
require.NoError(t, err)
ch := Child{
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, ophosttypes.QueryBridgeResponse{}, nil, nodetypes.NodeConfig{}),
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, opchildtypes.BridgeInfo{}, nil, nodetypes.NodeConfig{}),
host: tc.host,
challenger: tc.challenger,
stage: childdb.NewStage(),
Expand Down
4 changes: 2 additions & 2 deletions challenger/child/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

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

Expand Down
21 changes: 11 additions & 10 deletions challenger/child/withdraw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
ophosttypes "github.com/initia-labs/OPinit/x/ophost/types"
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
"github.com/initia-labs/opinit-bots/db"
Expand All @@ -22,7 +23,7 @@ import (
)

func TestInitiateWithdrawalHandler(t *testing.T) {
bridgeInfo := ophosttypes.QueryBridgeResponse{
bridgeInfo := opchildtypes.BridgeInfo{
BridgeId: 1,
}

Expand Down Expand Up @@ -160,7 +161,7 @@ func TestInitiateWithdrawalHandler(t *testing.T) {
}

func TestPrepareTree(t *testing.T) {
bridgeInfo := ophosttypes.QueryBridgeResponse{
bridgeInfo := opchildtypes.BridgeInfo{
BridgeId: 1,
}

Expand Down Expand Up @@ -304,15 +305,15 @@ func TestPrepareTree(t *testing.T) {
func TestPrepareOutput(t *testing.T) {
cases := []struct {
name string
bridgeInfo ophosttypes.QueryBridgeResponse
bridgeInfo opchildtypes.BridgeInfo
hostOutputs map[uint64]ophosttypes.Output
lastWorkingTree merkletypes.TreeInfo
expected func() (lastOutputTime time.Time, nextOutputTime time.Time, finalizingBlockHeight int64)
err bool
}{
{
name: "no output, index 1",
bridgeInfo: ophosttypes.QueryBridgeResponse{
bridgeInfo: opchildtypes.BridgeInfo{
BridgeId: 1,
BridgeConfig: ophosttypes.BridgeConfig{
SubmissionInterval: 100,
Expand All @@ -334,7 +335,7 @@ func TestPrepareOutput(t *testing.T) {
},
{
name: "no output, index 3", // chain rolled back
bridgeInfo: ophosttypes.QueryBridgeResponse{
bridgeInfo: opchildtypes.BridgeInfo{
BridgeId: 1,
BridgeConfig: ophosttypes.BridgeConfig{
SubmissionInterval: 100,
Expand All @@ -356,7 +357,7 @@ func TestPrepareOutput(t *testing.T) {
},
{
name: "outputs {1}, index 1", // sync
bridgeInfo: ophosttypes.QueryBridgeResponse{
bridgeInfo: opchildtypes.BridgeInfo{
BridgeId: 1,
BridgeConfig: ophosttypes.BridgeConfig{
SubmissionInterval: 100,
Expand All @@ -383,7 +384,7 @@ func TestPrepareOutput(t *testing.T) {
},
{
name: "outputs {1}, index 2",
bridgeInfo: ophosttypes.QueryBridgeResponse{
bridgeInfo: opchildtypes.BridgeInfo{
BridgeId: 1,
BridgeConfig: ophosttypes.BridgeConfig{
SubmissionInterval: 300,
Expand Down Expand Up @@ -452,7 +453,7 @@ func TestPrepareOutput(t *testing.T) {
}

func TestHandleTree(t *testing.T) {
bridgeInfo := ophosttypes.QueryBridgeResponse{
bridgeInfo := opchildtypes.BridgeInfo{
BridgeId: 1,
BridgeConfig: ophosttypes.BridgeConfig{
SubmissionInterval: 300,
Expand Down Expand Up @@ -683,7 +684,7 @@ func TestHandleOutput(t *testing.T) {
blockId []byte
outputIndex uint64
storageRoot []byte
bridgeInfo ophosttypes.QueryBridgeResponse
bridgeInfo opchildtypes.BridgeInfo
host *mockHost
expected []challengertypes.ChallengeEvent
err bool
Expand All @@ -696,7 +697,7 @@ func TestHandleOutput(t *testing.T) {
blockId: []byte("latestBlockHashlatestBlockHashla"),
outputIndex: 1,
storageRoot: []byte("storageRootstorageRootstorageRoo"),
bridgeInfo: ophosttypes.QueryBridgeResponse{BridgeId: 1},
bridgeInfo: opchildtypes.BridgeInfo{BridgeId: 1},
host: NewMockHost(nil, 5),
expected: []challengertypes.ChallengeEvent{
&challengertypes.Output{
Expand Down
51 changes: 51 additions & 0 deletions challenger/host/bridge_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package host

import (
"github.com/pkg/errors"
"go.uber.org/zap"

hostprovider "github.com/initia-labs/opinit-bots/provider/host"

nodetypes "github.com/initia-labs/opinit-bots/node/types"
"github.com/initia-labs/opinit-bots/types"
)

func (h *Host) updateProposerHandler(ctx types.Context, args nodetypes.EventHandlerArgs) error {
bridgeId, proposer, finalizedOutputIndex, finalizedL2BlockNumber, err := hostprovider.ParseMsgUpdateProposer(args.EventAttributes)
if err != nil {
return errors.Wrap(err, "failed to parse update proposer event")
}
if bridgeId != h.BridgeId() {
return nil
}

ctx.Logger().Warn("update proposer",
zap.Uint64("bridge_id", bridgeId),
zap.String("proposer", proposer),
zap.Uint64("finalized_output_index", finalizedOutputIndex),
zap.Uint64("finalized_l2_block_number", finalizedL2BlockNumber),
)

h.UpdateProposer(proposer)
return nil
}

func (h *Host) updateChallengerHandler(ctx types.Context, args nodetypes.EventHandlerArgs) error {
bridgeId, challenger, finalizedOutputIndex, finalizedL2BlockNumber, err := hostprovider.ParseMsgUpdateChallenger(args.EventAttributes)
if err != nil {
return errors.Wrap(err, "failed to parse update challenger event")
}
if bridgeId != h.BridgeId() {
return nil
}

ctx.Logger().Info("update challenger",
zap.Uint64("bridge_id", bridgeId),
zap.String("challenger", challenger),
zap.Uint64("finalized_output_index", finalizedOutputIndex),
zap.Uint64("finalized_l2_block_number", finalizedL2BlockNumber),
)

h.UpdateChallenger(challenger)
return nil
}
Loading

0 comments on commit 919d32b

Please sign in to comment.