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

update readme & configs #59

Merged
merged 2 commits into from
Dec 11, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To ensure compatibility with the node version, check the following versions:

| L1 Node | MiniMove | MiniWasm | MiniEVM |
| ------- | -------- | -------- | ------- |
| v0.6.1+ | v0.6.4+ | v0.6.4+ | v0.6.6+ |
| v0.6.4+ | v0.6.5+ | v0.6.5+ | v0.6.7+ |

### Build and Configure

Expand Down Expand Up @@ -85,7 +85,7 @@ opinitd reset-heights [bot-name]

### Reset Node Height

To reset bot's specific node height info to 0 , use the following command:
To reset bot's specific node height info to 0, use the following command:

```bash
opinitd reset-height [bot-name] [node-type]
Expand Down
22 changes: 18 additions & 4 deletions challenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ To configure the Challenger, fill in the values in the `~/.opinit/challenger.jso
// It can be useful when you don't want to use TxSearch.
"disable_auto_set_l1_height": false,
// L1StartHeight is the height to start the l1 node.
"l1_start_height": 0,
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
"l1_start_height": 1,
// L2StartHeight is the height to start the l2 node.
// If the latest height stored in the db is not 0, this config is ignored.
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.
// L1 starts from the block number of the output tx + 1
"l2_start_height": 0,
"l2_start_height": 1,
}
```

Expand Down Expand Up @@ -184,9 +184,23 @@ curl localhost:3001/status
### Challenges

```bash
curl localhost:3001/challenges/{page}
curl localhost:3001/challenges
```

default options
- `limit`: 10
- `offset`: ""
- `order`: desc

```go
type QueryChallengesResponse struct {
Challenges []Challenge `json:"challenges"`
Next *string `json:"next,omitempty"`
}
```

If `next` exists, you can continue querying by inserting it as the `offset`.

```json
[
{
Expand Down
47 changes: 24 additions & 23 deletions challenger/challenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ func (c *Challenger) Initialize(ctx types.Context) error {
zap.Duration("submission_interval", bridgeInfo.BridgeConfig.SubmissionInterval),
)

hostProcessedHeight, childProcessedHeight, processedOutputIndex, err := c.getProcessedHeights(ctx, bridgeInfo.BridgeId)
l1StartHeight, l2StartHeight, startOutputIndex, err := c.getNodeStartHeights(ctx, bridgeInfo.BridgeId)
if err != nil {
return err
}

var initialBlockTime time.Time
hostInitialBlockTime, err := c.host.Initialize(ctx, hostProcessedHeight, c.child, *bridgeInfo, c)
hostInitialBlockTime, err := c.host.Initialize(ctx, l1StartHeight-1, c.child, *bridgeInfo, c)
if err != nil {
return err
}
if initialBlockTime.Before(hostInitialBlockTime) {
initialBlockTime = hostInitialBlockTime
}

childInitialBlockTime, err := c.child.Initialize(ctx, childProcessedHeight, processedOutputIndex+1, c.host, *bridgeInfo, c)
childInitialBlockTime, err := c.child.Initialize(ctx, l2StartHeight-1, startOutputIndex, c.host, *bridgeInfo, c)
if err != nil {
return err
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func (c *Challenger) RegisterQuerier() {
return ctx.JSON(status)
})
c.server.RegisterQuerier("/challenges", func(ctx *fiber.Ctx) error {
next := ctx.Query("next", "")
offset := ctx.Query("offset", "")
limit := ctx.QueryInt("limit", 10)
if limit > 100 {
limit = 100
Expand All @@ -203,7 +203,7 @@ func (c *Challenger) RegisterQuerier() {
descOrder = false
}

res, err := c.QueryChallenges(next, ulimit, descOrder)
res, err := c.QueryChallenges(offset, ulimit, descOrder)
if err != nil {
return err
}
Expand All @@ -227,35 +227,39 @@ func (c *Challenger) RegisterQuerier() {
})
}

func (c *Challenger) getProcessedHeights(ctx types.Context, bridgeId uint64) (l1ProcessedHeight int64, l2ProcessedHeight int64, processedOutputIndex uint64, err error) {
func (c *Challenger) getNodeStartHeights(ctx types.Context, bridgeId uint64) (l1StartHeight int64, l2StartHeight int64, startOutputIndex uint64, err error) {
if c.host.Node().GetSyncedHeight() != 0 && c.child.Node().GetSyncedHeight() != 0 {
return 0, 0, 0, nil
}

var outputL1BlockNumber int64
var outputL1Height, outputL2Height int64
var outputIndex uint64

// get the last submitted output height before the start height from the host
if c.cfg.L2StartHeight != 0 {
if c.cfg.L2StartHeight > 1 {
output, err := c.host.QueryLastFinalizedOutput(ctx, bridgeId)
if err != nil {
return 0, 0, 0, err
} else if output != nil {
outputL1BlockNumber = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
l2ProcessedHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
processedOutputIndex = output.OutputIndex
outputL1Height = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
outputL2Height = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
outputIndex = output.OutputIndex
}
}
l2StartHeight = outputL2Height + 1
startOutputIndex = outputIndex + 1

if c.cfg.DisableAutoSetL1Height {
l1ProcessedHeight = c.cfg.L1StartHeight
l1StartHeight = c.cfg.L1StartHeight
} else {
// get the bridge start height from the host
l1ProcessedHeight, err = c.host.QueryCreateBridgeHeight(ctx, bridgeId)
l1StartHeight, err = c.host.QueryCreateBridgeHeight(ctx, bridgeId)
if err != nil {
return 0, 0, 0, err
}

if l2ProcessedHeight > 0 {
l1Sequence, err := c.child.QueryNextL1Sequence(ctx, l2ProcessedHeight-1)
if l2StartHeight > 1 {
l1Sequence, err := c.child.QueryNextL1Sequence(ctx, l2StartHeight-1)
if err != nil {
return 0, 0, 0, err
}
Expand All @@ -271,19 +275,16 @@ func (c *Challenger) getProcessedHeights(ctx types.Context, bridgeId uint64) (l1
}
}

if depositTxHeight > l1ProcessedHeight {
l1ProcessedHeight = depositTxHeight
if depositTxHeight > l1StartHeight {
l1StartHeight = depositTxHeight
}
if outputL1BlockNumber != 0 && outputL1BlockNumber < l1ProcessedHeight {
l1ProcessedHeight = outputL1BlockNumber
if outputL1Height != 0 && outputL1Height < l1StartHeight {
l1StartHeight = outputL1Height + 1
}
}
}
if l1ProcessedHeight > 0 {
l1ProcessedHeight--
}

return l1ProcessedHeight, l2ProcessedHeight, processedOutputIndex, err
return
}

func (c Challenger) DB() types.DB {
Expand Down
6 changes: 3 additions & 3 deletions challenger/query.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 (c *Challenger) QueryChallenges(from string, limit uint64, descOrder bool) (res challengertypes.QueryChallengesResponse, err error) {
func (c *Challenger) QueryChallenges(offset string, limit uint64, descOrder bool) (res challengertypes.QueryChallengesResponse, err error) {
challenges := []challengertypes.Challenge{}
next := ""

Expand All @@ -29,8 +29,8 @@ func (c *Challenger) QueryChallenges(from string, limit uint64, descOrder bool)
}

var startKey []byte
if from != "" {
startKey, err = base64.StdEncoding.DecodeString(from)
if offset != "" {
startKey, err = base64.StdEncoding.DecodeString(offset)
if err != nil {
return challengertypes.QueryChallengesResponse{}, err
}
Expand Down
12 changes: 6 additions & 6 deletions challenger/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func DefaultConfig() *Config {
RPCAddress: "tcp://localhost:27657",
},
DisableAutoSetL1Height: false,
L1StartHeight: 0,
L2StartHeight: 0,
L1StartHeight: 1,
L2StartHeight: 1,
}
}

Expand All @@ -101,12 +101,12 @@ func (cfg Config) Validate() error {
return err
}

if cfg.L1StartHeight < 0 {
return errors.New("l1 start height must be greater than or equal to 0")
if cfg.L1StartHeight <= 0 {
return errors.New("l1 start height must be greater than 0")
}

if cfg.L2StartHeight < 0 {
return errors.New("l2 start height must be greater than or equal to 0")
if cfg.L2StartHeight <= 0 {
return errors.New("l2 start height must be greater than 0")
}
return nil
}
Expand Down
53 changes: 30 additions & 23 deletions executor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
// It can be useful when you don't want to use TxSearch.
"disable_auto_set_l1_height": false,
// L1StartHeight is the height to start the l1 node.
"l1_start_height": 0,
// L2StartHeight is the height to start the l2 node. If it is 0, it will start from the latest height.
"l1_start_height": 1,
// L2StartHeight is the height to start the l2 node.
// If the latest height stored in the db is not 0, this config is ignored.
// L2 starts from the last submitted output l2 block number + 1 before L2StartHeight.
// L1 starts from the block number of the output tx + 1
"l2_start_height": 0,
// StartBatchHeight is the height to start the batch. If it is 0, it will start from the latest height.
"l2_start_height": 1,
// StartBatchHeight is the height to start the batch.
// If the latest height stored in the db is not 0, this config is ignored.
"batch_start_height": 0,
"batch_start_height": 1,
// DisableDeleteFutureWithdrawal is the flag to disable the deletion of future withdrawal.
// when the bot is rolled back, it will delete the future withdrawals from DB.
// If it is true, it will not delete the future withdrawals.
Expand Down Expand Up @@ -229,21 +229,22 @@ When a tree is finalized, `Child` stores the leaf nodes and internal nodes of th

```go
type QueryWithdrawalResponse struct {
// fields required to withdraw funds
BridgeId uint64 `json:"bridge_id"`
OutputIndex uint64 `json:"output_index"`
WithdrawalProofs [][]byte `json:"withdrawal_proofs"`
Sender string `json:"sender"`
Sequence uint64 `json:"sequence"`
Amount string `json:"amount"`
Version []byte `json:"version"`
StorageRoot []byte `json:"storage_root"`
LatestBlockHash []byte `json:"latest_block_hash"`

// extra info
BlockNumber int64 `json:"block_number"`
Receiver string `json:"receiver"`
WithdrawalHash []byte `json:"withdrawal_hash"`
// fields required to withdraw funds
Sequence uint64 `json:"sequence"`
To string `json:"to"`
From string `json:"from"`
Amount types.Coin `json:"amount"`
OutputIndex uint64 `json:"output_index"`
BridgeId uint64 `json:"bridge_id"`
WithdrawalProofs [][]byte `json:"withdrawal_proofs"`
Version []byte `json:"version"`
StorageRoot []byte `json:"storage_root"`
LastBlockHash []byte `json:"last_block_hash"`

// extra info
TxTime int64 `json:"tx_time"`
TxHeight int64 `json:"tx_height"`
TxHash string `json:"tx_hash"`
}
```

Expand Down Expand Up @@ -414,7 +415,7 @@ curl localhost:3000/status
### Withdrawals

```bash
curl localhost:3000/withdrawal/{sequence} | jq . > ./withdrawal-info.json
curl localhost:3000/withdrawal/{sequence} | jq 'del(.tx_time, .tx_height, .tx_hash)' > ./withdrawal-info.json
initiad tx ophost finalize-token-withdrawal ./withdrawal-info.json --gas= --gas-prices= --chain-id= --from=
```

Expand All @@ -430,6 +431,11 @@ type QueryWithdrawalResponse struct {
Version []byte `json:"version"`
StorageRoot []byte `json:"storage_root"`
LastBlockHash []byte `json:"last_block_hash"`

// extra info
TxTime int64 `json:"tx_time"`
TxHeight int64 `json:"tx_height"`
TxHash string `json:"tx_hash"`
}
```

Expand All @@ -446,6 +452,7 @@ default options
type QueryWithdrawalsResponse struct {
Withdrawals []QueryWithdrawalResponse `json:"withdrawals"`
Next uint64 `json:"next"`
Total uint64 `json:"total"`
}
```
```

If `next` exists, you can continue querying by inserting it as the `offset`.
1 change: 0 additions & 1 deletion node/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (n *Node) blockProcessLooper(ctx types.Context, processType nodetypes.Block

latestHeight := status.SyncInfo.LatestBlockHeight
if n.syncedHeight >= latestHeight {
ctx.Logger().Warn("already synced", zap.Int64("synced_height", n.syncedHeight), zap.Int64("latest_height", latestHeight))
continue
}

Expand Down
7 changes: 3 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ type Server struct {
func NewServer(cfg types.ServerConfig) *Server {
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: cfg.AllowOrigins,
AllowHeaders: cfg.AllowHeaders,
AllowMethods: cfg.AllowMethods,
AllowCredentials: true,
AllowOrigins: cfg.AllowOrigins,
AllowHeaders: cfg.AllowHeaders,
AllowMethods: cfg.AllowMethods,
}))

return &Server{
Expand Down
Loading