Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apply connect-v2 updates #20

Merged
merged 5 commits into from
Sep 26, 2024
Merged
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
10 changes: 1 addition & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ concurrency:
jobs:
golangci:
env:
GOPRIVATE: github.com/initia-labs
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
GOLANGCI_LINT_VERSION: v1.59.1
GOLANGCI_LINT_VERSION: v1.61.0
name: golangci-lint
runs-on: ubuntu-latest
steps:
Expand All @@ -41,7 +39,6 @@ jobs:
**/**.go
go.mod
go.sum
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
# install golangci-lint
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
- name: run go linters (long)
Expand All @@ -68,10 +65,6 @@ jobs:
# Use --check or --exit-code when available (Go 1.19?)
# https://github.com/golang/go/issues/27005
tidy:
env:
# for private repo access
GOPRIVATE: github.com/initia-labs,github.com/skip-mev/slinky
GITHUB_ACCESS_TOKEN: ${{ secrets.GH_READ_TOKEN }}
runs-on: ubuntu-latest
name: tidy
steps:
Expand All @@ -81,7 +74,6 @@ jobs:
with:
go-version: 1.22
check-latest: true
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- run: |
go mod tidy
CHANGES_IN_REPO=$(git status --porcelain)
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Before running OPinit bots, make sure you have the following prerequisites insta

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

| L1 Node | MiniMove | MiniWasm | MiniEVM |
| ------- | -------- | -------- | ------- |
| v0.4.9 | v0.4.2 | v0.4.2 | - |
| L1 Node | MiniMove | MiniWasm | MiniEVM |
| ------- | -------- | -------- | ------- |
| v0.5.1 | v0.5.1 | v0.5.1 | v0.5.1 |

### Build and Configure

Expand Down Expand Up @@ -60,7 +60,8 @@ To start the bot, use the following command:
opinitd start [bot-name]
```

Options
Options

- `--log-level`: log level can be set. Default log level is `info`.
- `--polling-interval`: polling interval can be set. Default polling interval is `100ms`.
- `--config`: config file name can be set. Default config file name is `[bot-name].json`.
Expand Down
4 changes: 2 additions & 2 deletions challenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ When the `initiate_token_deposit` event is detected in l1, saves it as a `Deposi
type Deposit struct {
EventType string `json:"event_type"`
Sequence uint64 `json:"sequence"`
L1BlockHeight uint64 `json:"l1_block_height"`
L1BlockHeight int64 `json:"l1_block_height"`
From string `json:"from"`
To string `json:"to"`
L1Denom string `json:"l1_denom"`
Expand All @@ -101,7 +101,7 @@ When the `propose_output` event is detected in l1, saves it as a `Output` challe
// Output is the challenge event for the output
type Output struct {
EventType string `json:"event_type"`
L2BlockNumber uint64 `json:"l2_block_number"`
L2BlockNumber int64 `json:"l2_block_number"`
OutputIndex uint64 `json:"output_index"`
OutputRoot []byte `json:"output_root"`
Time time.Time `json:"time"`
Expand Down
6 changes: 3 additions & 3 deletions challenger/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (c *Challenger) RegisterQuerier() {
})
}

func (c *Challenger) getStartHeights(ctx context.Context, bridgeId uint64) (l1StartHeight uint64, l2StartHeight uint64, startOutputIndex uint64, err error) {
func (c *Challenger) getStartHeights(ctx context.Context, bridgeId uint64) (l1StartHeight int64, l2StartHeight int64, startOutputIndex uint64, err error) {
// get the bridge start height from the host
l1StartHeight, err = c.host.QueryCreateBridgeHeight(ctx, bridgeId)
if err != nil {
Expand All @@ -205,8 +205,8 @@ func (c *Challenger) getStartHeights(ctx context.Context, bridgeId uint64) (l1St
if err != nil {
return 0, 0, 0, err
} else if output != nil {
l1StartHeight = output.OutputProposal.L1BlockNumber
l2StartHeight = output.OutputProposal.L2BlockNumber
l1StartHeight = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
l2StartHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
startOutputIndex = output.OutputIndex + 1
}
}
Expand Down
8 changes: 4 additions & 4 deletions challenger/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ type Child struct {

eventQueue []challengertypes.ChallengeEvent

finalizingBlockHeight uint64
finalizingBlockHeight int64

// status info
lastUpdatedOracleL1Height uint64
lastFinalizedDepositL1BlockHeight uint64
lastUpdatedOracleL1Height int64
lastFinalizedDepositL1BlockHeight int64
lastFinalizedDepositL1Sequence uint64
lastOutputTime time.Time
nextOutputTime time.Time
Expand All @@ -56,7 +56,7 @@ func NewChildV1(
}
}

func (ch *Child) Initialize(ctx context.Context, startHeight uint64, startOutputIndex uint64, host hostNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
func (ch *Child) Initialize(ctx context.Context, startHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
_, err := ch.BaseChild.Initialize(ctx, startHeight, startOutputIndex, bridgeInfo)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions challenger/child/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func (ch *Child) finalizeDepositHandler(_ context.Context, args nodetypes.EventH
return nil
}

func (ch *Child) handleFinalizeDeposit(l2BlockTime time.Time, l1BlockHeight uint64, l1Sequence uint64, from string, to string, amount sdk.Coin, baseDenom string) {
func (ch *Child) handleFinalizeDeposit(l2BlockTime time.Time, l1BlockHeight int64, l1Sequence uint64, from string, to string, amount sdk.Coin, baseDenom string) {
deposit := challengertypes.NewDeposit(l1Sequence, l1BlockHeight, from, to, baseDenom, amount.String(), l2BlockTime)
ch.eventQueue = append(ch.eventQueue, deposit)

ch.Logger().Info("finalize token deposit",
zap.Uint64("l1_blockHeight", l1BlockHeight),
zap.Int64("l1_blockHeight", l1BlockHeight),
zap.Uint64("l1_sequence", l1Sequence),
zap.String("from", from),
zap.String("to", to),
Expand Down
6 changes: 3 additions & 3 deletions challenger/child/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (ch *Child) beginBlockHandler(ctx context.Context, args nodetypes.BeginBlockArgs) (err error) {
blockHeight := uint64(args.Block.Header.Height)
blockHeight := args.Block.Header.Height
ch.eventQueue = ch.eventQueue[:0]

err = ch.prepareTree(blockHeight)
Expand All @@ -28,7 +28,7 @@ func (ch *Child) beginBlockHandler(ctx context.Context, args nodetypes.BeginBloc
}

func (ch *Child) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) error {
blockHeight := uint64(args.Block.Header.Height)
blockHeight := args.Block.Header.Height
batchKVs := make([]types.RawKV, 0)
pendingChallenges := make([]challengertypes.Challenge, 0)

Expand Down Expand Up @@ -109,6 +109,6 @@ func (ch *Child) txHandler(_ context.Context, args nodetypes.TxHandlerArgs) erro
if !ok {
return nil
}
ch.oracleTxHandler(args.BlockTime, msg.Sender, msg.Height, msg.Data)
ch.oracleTxHandler(args.BlockTime, msg.Sender, types.MustUint64ToInt64(msg.Height), msg.Data)
return nil
}
4 changes: 2 additions & 2 deletions challenger/child/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"go.uber.org/zap"
)

func (ch *Child) oracleTxHandler(blockTime time.Time, sender string, l1BlockHeight uint64, oracleDataBytes comettypes.Tx) {
func (ch *Child) oracleTxHandler(blockTime time.Time, sender string, l1BlockHeight int64, oracleDataBytes comettypes.Tx) {
checksum := challengertypes.OracleChecksum(oracleDataBytes)
oracle := challengertypes.NewOracle(l1BlockHeight, checksum, blockTime)
ch.eventQueue = append(ch.eventQueue, oracle)
ch.lastUpdatedOracleL1Height = l1BlockHeight

ch.Logger().Info("update oracle",
zap.Uint64("l1_blockHeight", l1BlockHeight),
zap.Int64("l1_blockHeight", l1BlockHeight),
zap.String("from", sender),
)
}
6 changes: 3 additions & 3 deletions challenger/child/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

type Status struct {
Node nodetypes.Status `json:"node"`
LastUpdatedOracleL1Height uint64 `json:"last_updated_oracle_height"`
LastFinalizedDepositL1BlockHeight uint64 `json:"last_finalized_deposit_l1_block_height"`
LastUpdatedOracleL1Height int64 `json:"last_updated_oracle_height"`
LastFinalizedDepositL1BlockHeight int64 `json:"last_finalized_deposit_l1_block_height"`
LastFinalizedDepositL1Sequence uint64 `json:"last_finalized_deposit_l1_sequence"`
LastWithdrawalL2Sequence uint64 `json:"last_withdrawal_l2_sequence"`
WorkingTreeIndex uint64 `json:"working_tree_index"`

FinalizingBlockHeight uint64 `json:"finalizing_block_height"`
FinalizingBlockHeight int64 `json:"finalizing_block_height"`
LastOutputSubmissionTime time.Time `json:"last_output_submission_time"`
NextOutputSubmissionTime time.Time `json:"next_output_submission_time"`

Expand Down
14 changes: 7 additions & 7 deletions challenger/child/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func (ch *Child) handleInitiateWithdrawal(l2Sequence uint64, from string, to str
return nil
}

func (ch *Child) prepareTree(blockHeight uint64) error {
func (ch *Child) prepareTree(blockHeight int64) error {
if ch.InitializeTree(blockHeight) {
return nil
}

err := ch.Merkle().LoadWorkingTree(blockHeight - 1)
err := ch.Merkle().LoadWorkingTree(types.MustInt64ToUint64(blockHeight - 1))
if err == dbtypes.ErrNotFound {
// must not happened
panic(fmt.Errorf("working tree not found at height: %d, current: %d", blockHeight-1, blockHeight))
Expand Down Expand Up @@ -110,12 +110,12 @@ func (ch *Child) prepareOutput(ctx context.Context) error {
return err
} else {
ch.nextOutputTime = output.OutputProposal.L1BlockTime
ch.finalizingBlockHeight = output.OutputProposal.L2BlockNumber
ch.finalizingBlockHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
}
return nil
}

func (ch *Child) handleTree(blockHeight uint64, blockHeader cmtproto.Header) (kvs []types.RawKV, storageRoot []byte, err error) {
func (ch *Child) handleTree(blockHeight int64, blockHeader cmtproto.Header) (kvs []types.RawKV, storageRoot []byte, err error) {
// panic if we passed the finalizing block height
// this must not happened
if ch.finalizingBlockHeight != 0 && ch.finalizingBlockHeight < blockHeight {
Expand All @@ -130,7 +130,7 @@ func (ch *Child) handleTree(blockHeight uint64, blockHeader cmtproto.Header) (kv

ch.Logger().Info("finalize working tree",
zap.Uint64("tree_index", ch.Merkle().GetWorkingTreeIndex()),
zap.Uint64("height", blockHeight),
zap.Int64("height", blockHeight),
zap.Uint64("num_leaves", ch.Merkle().GetWorkingTreeLeafCount()),
zap.String("storage_root", base64.StdEncoding.EncodeToString(storageRoot)),
)
Expand All @@ -139,15 +139,15 @@ func (ch *Child) handleTree(blockHeight uint64, blockHeader cmtproto.Header) (kv
ch.lastOutputTime = blockHeader.Time
}

err = ch.Merkle().SaveWorkingTree(blockHeight)
err = ch.Merkle().SaveWorkingTree(types.MustInt64ToUint64(blockHeight))
if err != nil {
return nil, nil, err
}

return kvs, storageRoot, nil
}

func (ch *Child) handleOutput(blockTime time.Time, blockHeight uint64, version uint8, blockId []byte, outputIndex uint64, storageRoot []byte) error {
func (ch *Child) handleOutput(blockTime time.Time, blockHeight int64, version uint8, blockId []byte, outputIndex uint64, storageRoot []byte) error {
outputRoot := ophosttypes.GenerateOutputRoot(version, storageRoot, blockId)
output := challengertypes.NewOutput(blockHeight, outputIndex, outputRoot[:], blockTime)

Expand Down
2 changes: 1 addition & 1 deletion challenger/host/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (h *Host) initiateDepositHandler(_ context.Context, args nodetypes.EventHan

func (h *Host) handleInitiateDeposit(
l1Sequence uint64,
blockHeight uint64,
blockHeight int64,
blockTime time.Time,
from string,
to string,
Expand Down
2 changes: 1 addition & 1 deletion challenger/host/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (h *Host) beginBlockHandler(_ context.Context, args nodetypes.BeginBlockArg
}

func (h *Host) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) error {
blockHeight := uint64(args.Block.Header.Height)
blockHeight := args.Block.Header.Height
batchKVs := []types.RawKV{
h.Node().SyncInfoToRawKV(blockHeight),
}
Expand Down
2 changes: 1 addition & 1 deletion challenger/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewHostV1(
}
}

func (h *Host) Initialize(ctx context.Context, startHeight uint64, child childNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
func (h *Host) Initialize(ctx context.Context, startHeight int64, child childNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
err := h.BaseHost.Initialize(ctx, startHeight, bridgeInfo)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion challenger/host/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
)

func (h *Host) oracleTxHandler(blockHeight uint64, blockTime time.Time, oracleDataBytes comettypes.Tx) {
func (h *Host) oracleTxHandler(blockHeight int64, blockTime time.Time, oracleDataBytes comettypes.Tx) {
if !h.OracleEnabled() {
return
}
Expand Down
4 changes: 2 additions & 2 deletions challenger/host/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (h *Host) proposeOutputHandler(_ context.Context, args nodetypes.EventHandl
return h.handleProposeOutput(bridgeId, proposer, outputIndex, l2BlockNumber, outputRoot, args.BlockTime)
}

func (h *Host) handleProposeOutput(bridgeId uint64, proposer string, outputIndex uint64, l2BlockNumber uint64, outputRoot []byte, blockTime time.Time) error {
func (h *Host) handleProposeOutput(bridgeId uint64, proposer string, outputIndex uint64, l2BlockNumber int64, outputRoot []byte, blockTime time.Time) error {
output := challengertypes.NewOutput(l2BlockNumber, outputIndex, outputRoot[:], blockTime)

h.lastOutputIndex = outputIndex
Expand All @@ -36,7 +36,7 @@ func (h *Host) handleProposeOutput(bridgeId uint64, proposer string, outputIndex
zap.Uint64("bridge_id", bridgeId),
zap.String("proposer", proposer),
zap.Uint64("output_index", outputIndex),
zap.Uint64("l2_block_number", l2BlockNumber),
zap.Int64("l2_block_number", l2BlockNumber),
zap.String("output_root", base64.StdEncoding.EncodeToString(outputRoot)),
)
return nil
Expand Down
16 changes: 9 additions & 7 deletions challenger/types/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"fmt"
"time"

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

type Challenge struct {
Expand Down Expand Up @@ -94,7 +96,7 @@ func (e EventType) String() string {
type Deposit struct {
EventType string `json:"event_type"`
Sequence uint64 `json:"sequence"`
L1BlockHeight uint64 `json:"l1_block_height"`
L1BlockHeight int64 `json:"l1_block_height"`
From string `json:"from"`
To string `json:"to"`
L1Denom string `json:"l1_denom"`
Expand All @@ -105,7 +107,7 @@ type Deposit struct {

var _ ChallengeEvent = &Deposit{}

func NewDeposit(sequence, l1BlockHeight uint64, from, to, l1Denom, amount string, time time.Time) *Deposit {
func NewDeposit(sequence uint64, l1BlockHeight int64, from, to, l1Denom, amount string, time time.Time) *Deposit {
d := &Deposit{
Sequence: sequence,
L1BlockHeight: l1BlockHeight,
Expand Down Expand Up @@ -169,7 +171,7 @@ func (d Deposit) IsTimeout() bool {

type Output struct {
EventType string `json:"event_type"`
L2BlockNumber uint64 `json:"l2_block_number"`
L2BlockNumber int64 `json:"l2_block_number"`
OutputIndex uint64 `json:"output_index"`
OutputRoot []byte `json:"output_root"`
Time time.Time `json:"time"`
Expand All @@ -178,7 +180,7 @@ type Output struct {

var _ ChallengeEvent = &Output{}

func NewOutput(l2BlockNumber, outputIndex uint64, outputRoot []byte, time time.Time) *Output {
func NewOutput(l2BlockNumber int64, outputIndex uint64, outputRoot []byte, time time.Time) *Output {
o := &Output{
L2BlockNumber: l2BlockNumber,
OutputIndex: outputIndex,
Expand Down Expand Up @@ -235,13 +237,13 @@ func (o Output) IsTimeout() bool {

type Oracle struct {
EventType string `json:"event_type"`
L1Height uint64 `json:"l1_height"`
L1Height int64 `json:"l1_height"`
Data []byte `json:"data"`
Time time.Time `json:"time"`
Timeout bool `json:"timeout"`
}

func NewOracle(l1Height uint64, data []byte, time time.Time) *Oracle {
func NewOracle(l1Height int64, data []byte, time time.Time) *Oracle {
o := &Oracle{
L1Height: l1Height,
Data: data,
Expand Down Expand Up @@ -283,7 +285,7 @@ func (o Oracle) EventTime() time.Time {
func (o Oracle) Id() ChallengeId {
return ChallengeId{
Type: EventTypeOracle,
Id: o.L1Height,
Id: types.MustInt64ToUint64(o.L1Height),
}
}

Expand Down
3 changes: 2 additions & 1 deletion challenger/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

dbtypes "github.com/initia-labs/opinit-bots/db/types"
"github.com/initia-labs/opinit-bots/types"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -34,7 +35,7 @@ func PrefixedPendingChallenge(id ChallengeId) []byte {
}

func PrefixedTimeEventTypeId(eventTime time.Time, id ChallengeId) []byte {
return append(append(dbtypes.FromUint64Key(uint64(eventTime.UnixNano())), dbtypes.Splitter),
return append(append(dbtypes.FromUint64Key(types.MustInt64ToUint64(eventTime.UnixNano())), dbtypes.Splitter),
PrefixedEventTypeId(id.Type, id.Id)...)
}

Expand Down
Loading
Loading