Skip to content

Commit 88491e9

Browse files
authored
Feat/split oracletx (#45)
* find tx using txsearch with tx hash * change sequence * add oracle executor account to avoid executor sequence mismatch * query block header instead of block * handle tx failed * remove redunt sequence err * update readme * return sender when creating msgs & split msg queue every sender * set bridge info first * update authz grant checker * add sender * add broadcaster account checker * sender not set bug fix * delete debug print * add sender to pendingtx * add sender when unmarshalling processed msgs * remove redundant msg queue allocation * format * delete processed msgs from db when simulation failed and error is handled * change oracle tx sender * change proof query error (#46) * enable to query withdrawals that their tree is not finalized yet (#47) * introduce authz tx msg command (#48) * introduce authz tx msg command * update readme * format * update evm version * can disable to relay oracle data by emptying oracle-bridge-executor
1 parent 5f2e7de commit 88491e9

Some content is hidden

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

49 files changed

+1208
-624
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To ensure compatibility with the node version, check the following versions:
1919

2020
| L1 Node | MiniMove | MiniWasm | MiniEVM |
2121
| ------- | -------- | -------- | ------- |
22-
| v0.5.3+ | v0.5.3+ | v0.5.2+ | v0.5.2+ |
22+
| v0.6.1+ | v0.6.4+ | v0.6.4+ | v0.6.6+ |
2323

2424
### Build and Configure
2525

challenger/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ To configure the Challenger, fill in the values in the `~/.opinit/challenger.jso
1818
// Version is the version used to build output root.
1919
// Please refer to `spec_version.json` for the correct version for each network.
2020
"version": 1,
21-
// ListenAddress is the address to listen for incoming requests.
22-
"listen_address": "localhost:3001",
21+
// Server is the configuration for the server.
22+
"server": {
23+
"address": "localhost:3000",
24+
"allow_origins": "*",
25+
"allow_headers": "Origin, Content-Type, Accept",
26+
"allow_methods": "GET",
27+
},
2328
"l1_node": {
2429
"chain_id": "testnet-l1-1",
2530
"bech32_prefix": "init",

challenger/child/child.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewChildV1(
5757
}
5858

5959
func (ch *Child) Initialize(ctx context.Context, processedHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo ophosttypes.QueryBridgeResponse, challenger challenger) (time.Time, error) {
60-
_, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, nil)
60+
_, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, nil, nil)
6161
if err != nil {
6262
return time.Time{}, err
6363
}

cmd/opinitd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func NewRootCmd() *cobra.Command {
4949
resetHeightsCmd(ctx),
5050
resetHeightCmd(ctx),
5151
migration015Cmd(ctx),
52+
txCmd(ctx),
5253
version.NewVersionCommand(),
5354
)
5455
return rootCmd

cmd/opinitd/tx.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"cosmossdk.io/errors"
9+
"github.com/spf13/cobra"
10+
"golang.org/x/sync/errgroup"
11+
12+
"github.com/cosmos/cosmos-sdk/x/authz"
13+
14+
"github.com/initia-labs/opinit-bots/bot"
15+
bottypes "github.com/initia-labs/opinit-bots/bot/types"
16+
executortypes "github.com/initia-labs/opinit-bots/executor/types"
17+
"github.com/initia-labs/opinit-bots/keys"
18+
"github.com/initia-labs/opinit-bots/node/broadcaster"
19+
broadcastertypes "github.com/initia-labs/opinit-bots/node/broadcaster/types"
20+
"github.com/initia-labs/opinit-bots/node/rpcclient"
21+
"github.com/initia-labs/opinit-bots/provider/child"
22+
"github.com/initia-labs/opinit-bots/types"
23+
24+
sdk "github.com/cosmos/cosmos-sdk/types"
25+
)
26+
27+
// txCmd represents the tx command
28+
func txCmd(ctx *cmdContext) *cobra.Command {
29+
cmd := &cobra.Command{
30+
Use: "tx",
31+
Short: "send a transaction",
32+
}
33+
34+
cmd.AddCommand(
35+
txGrantOracleCmd(ctx),
36+
)
37+
return cmd
38+
}
39+
40+
func txGrantOracleCmd(baseCtx *cmdContext) *cobra.Command {
41+
cmd := &cobra.Command{
42+
Use: "grant-oracle [oracle-account-address]",
43+
Args: cobra.ExactArgs(1),
44+
Short: "Grant oracle permission to the given account",
45+
Long: `Grant oracle permission to the given account on L2 chain`,
46+
RunE: func(cmd *cobra.Command, args []string) error {
47+
cmdCtx, botDone := context.WithCancel(cmd.Context())
48+
gracefulShutdown(botDone)
49+
50+
errGrp, ctx := errgroup.WithContext(cmdCtx)
51+
ctx = types.WithErrGrp(ctx, errGrp)
52+
53+
account, err := l2BroadcasterAccount(baseCtx, cmd)
54+
if err != nil {
55+
return err
56+
}
57+
err = account.Load(ctx)
58+
if err != nil {
59+
return err
60+
}
61+
62+
oracleAddress, err := keys.DecodeBech32AccAddr(args[0], account.Bech32Prefix())
63+
if err != nil {
64+
return err
65+
}
66+
67+
grantMsg, err := authz.NewMsgGrant(account.GetAddress(), oracleAddress, authz.NewGenericAuthorization(types.MsgUpdateOracleTypeUrl), nil)
68+
if err != nil {
69+
return err
70+
}
71+
72+
txBytes, _, err := account.BuildTxWithMessages(ctx, []sdk.Msg{grantMsg})
73+
if err != nil {
74+
return errors.Wrapf(err, "simulation failed")
75+
}
76+
77+
res, err := account.BroadcastTxSync(ctx, txBytes)
78+
if err != nil {
79+
// TODO: handle error, may repeat sending tx
80+
return fmt.Errorf("broadcast txs: %w", err)
81+
}
82+
bz, err := json.Marshal(res)
83+
if err != nil {
84+
return err
85+
}
86+
fmt.Println(string(bz))
87+
return nil
88+
},
89+
}
90+
91+
cmd = configFlag(baseCtx.v, cmd)
92+
return cmd
93+
}
94+
95+
func l2BroadcasterAccount(ctx *cmdContext, cmd *cobra.Command) (*broadcaster.BroadcasterAccount, error) {
96+
configPath, err := getConfigPath(cmd, ctx.homePath, string(bottypes.BotTypeExecutor))
97+
if err != nil {
98+
return nil, err
99+
}
100+
101+
cfg := &executortypes.Config{}
102+
err = bot.LoadJsonConfig(configPath, cfg)
103+
if err != nil {
104+
return nil, err
105+
}
106+
107+
l2Config := cfg.L2NodeConfig(ctx.homePath)
108+
broadcasterConfig := l2Config.BroadcasterConfig
109+
cdc, txConfig, err := child.GetCodec(broadcasterConfig.Bech32Prefix)
110+
if err != nil {
111+
return nil, err
112+
}
113+
114+
rpcClient, err := rpcclient.NewRPCClient(cdc, l2Config.RPC)
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
keyringConfig := broadcastertypes.KeyringConfig{
120+
Name: cfg.BridgeExecutor,
121+
}
122+
123+
return broadcaster.NewBroadcasterAccount(*broadcasterConfig, cdc, txConfig, rpcClient, keyringConfig)
124+
}

executor/README.md

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
1616
// Version is the version used to build output root.
1717
// Please refer to `spec_version.json` for the correct version for each network.
1818
"version": 1,
19-
// ListenAddress is the address to listen for incoming requests.
20-
"listen_address": "localhost:3000",
19+
// Server is the configuration for the server.
20+
"server": {
21+
"address": "localhost:3000",
22+
"allow_origins": "*",
23+
"allow_headers": "Origin, Content-Type, Accept",
24+
"allow_methods": "GET",
25+
},
2126
"l1_node": {
2227
"chain_id": "testnet-l1-1",
2328
"bech32_prefix": "init",
@@ -47,6 +52,11 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
4752
//
4853
// If you don't want to use the bridge executor feature, you can leave it empty.
4954
"bridge_executor": "",
55+
// OracleBridgeExecutor is the key name in the keyring for the oracle bridge executor,
56+
// which is used to relay oracle transaction from l1 to l2.
57+
//
58+
// If L2 is using oracle, you need to set this field.
59+
"oracle_bridge_executor": "",
5060

5161
// DisableOutputSubmitter is the flag to disable the output submitter.
5262
// If it is true, the output submitter will not be started.
@@ -80,6 +90,14 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
8090
}
8191
```
8292

93+
### Oracle config
94+
If you want to enable to relay oracle data, the `oracle_bridge_executor` field must be set. The oracle data is stored in the 0th tx of each L1 block. The bridge executor submits a `MsgUpdateOracle` containing the 0th Tx of l1 block to l2 when a block in l1 is created.
95+
96+
The `oracle_bridge_executor` must be an account that has received the authz grant from the executor. If it is not set, you can set the authz with the command below.
97+
```bash
98+
opinitd tx grant-oracle [oracle-account-address]
99+
```
100+
83101
### Start height config examples
84102

85103
If the latest height stored in the db is not 0, start height config is ignored.
@@ -319,13 +337,18 @@ curl localhost:3000/status
319337

320338
```json
321339
{
322-
"bridge_id": 1,
340+
"bridge_id": 0,
323341
"host": {
324342
"node": {
325343
"last_block_height": 0,
326344
"broadcaster": {
327345
"pending_txs": 0,
328-
"sequence": 0
346+
"accounts_status": [
347+
{
348+
"address": "",
349+
"sequence": 0
350+
}
351+
]
329352
}
330353
},
331354
"last_proposed_output_index": 0,
@@ -336,7 +359,16 @@ curl localhost:3000/status
336359
"last_block_height": 0,
337360
"broadcaster": {
338361
"pending_txs": 0,
339-
"sequence": 0
362+
"accounts_status": [
363+
{
364+
"address": "",
365+
"sequence": 0
366+
},
367+
{
368+
"address": "",
369+
"sequence": 0
370+
}
371+
]
340372
}
341373
},
342374
"last_updated_oracle_height": 0,
@@ -350,7 +382,7 @@ curl localhost:3000/status
350382
},
351383
"batch": {
352384
"node": {
353-
"last_block_height": 0,
385+
"last_block_height": 0
354386
},
355387
"batch_info": {
356388
"submitter": "",
@@ -364,7 +396,12 @@ curl localhost:3000/status
364396
"da": {
365397
"broadcaster": {
366398
"pending_txs": 0,
367-
"sequence": 0
399+
"accounts_status": [
400+
{
401+
"address": "",
402+
"sequence": 0
403+
}
404+
]
368405
}
369406
}
370407
}
@@ -379,20 +416,32 @@ initiad tx ophost finalize-token-withdrawal ./withdrawal-info.json --gas= --gas-
379416

380417
```go
381418
type QueryWithdrawalResponse struct {
382-
// fields required to withdraw funds
383-
BridgeId uint64 `json:"bridge_id"`
384-
OutputIndex uint64 `json:"output_index"`
385-
WithdrawalProofs [][]byte `json:"withdrawal_proofs"`
386-
Sender string `json:"sender"`
387-
Sequence uint64 `json:"sequence"`
388-
Amount string `json:"amount"`
389-
Version []byte `json:"version"`
390-
StorageRoot []byte `json:"storage_root"`
391-
LatestBlockHash []byte `json:"latest_block_hash"`
392-
393-
// extra info
394-
BlockNumber int64 `json:"block_number"`
395-
Receiver string `json:"receiver"`
396-
WithdrawalHash []byte `json:"withdrawal_hash"`
419+
Sequence uint64 `json:"sequence"`
420+
To string `json:"to"`
421+
From string `json:"from"`
422+
Amount types.Coin `json:"amount"`
423+
OutputIndex uint64 `json:"output_index"`
424+
BridgeId uint64 `json:"bridge_id"`
425+
WithdrawalProofs [][]byte `json:"withdrawal_proofs"`
426+
Version []byte `json:"version"`
427+
StorageRoot []byte `json:"storage_root"`
428+
LastBlockHash []byte `json:"last_block_hash"`
397429
}
398430
```
431+
432+
```bash
433+
curl localhost:3000/withdrawals/{address}
434+
```
435+
default options
436+
- `limit`: 10
437+
- `offset`: 0
438+
- `order`: desc
439+
440+
441+
```go
442+
type QueryWithdrawalsResponse struct {
443+
Withdrawals []QueryWithdrawalResponse `json:"withdrawals"`
444+
Next uint64 `json:"next"`
445+
Total uint64 `json:"total"`
446+
}
447+
```

executor/batch/handler.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight int64)
201201
checksums,
202202
)
203203

204-
msg, err := bs.da.CreateBatchMsg(headerData)
204+
msg, sender, err := bs.da.CreateBatchMsg(headerData)
205205
if err != nil {
206206
return err
207207
} else if msg != nil {
208208
bs.processedMsgs = append(bs.processedMsgs, btypes.ProcessedMsgs{
209+
Sender: sender,
209210
Msgs: []sdk.Msg{msg},
210211
Timestamp: time.Now().UnixNano(),
211212
Save: true,
@@ -220,11 +221,12 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight int64)
220221
types.MustInt64ToUint64(int64(len(checksums))),
221222
chunk,
222223
)
223-
msg, err := bs.da.CreateBatchMsg(chunkData)
224+
msg, sender, err := bs.da.CreateBatchMsg(chunkData)
224225
if err != nil {
225226
return err
226227
} else if msg != nil {
227228
bs.processedMsgs = append(bs.processedMsgs, btypes.ProcessedMsgs{
229+
Sender: sender,
228230
Msgs: []sdk.Msg{msg},
229231
Timestamp: time.Now().UnixNano(),
230232
Save: true,

executor/batch/noop_da.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ func NewNoopDA() *NoopDA {
2020
return &NoopDA{}
2121
}
2222

23-
func (n NoopDA) Start(_ context.Context) {}
24-
func (n NoopDA) HasKey() bool { return false }
25-
func (n NoopDA) CreateBatchMsg(_ []byte) (sdk.Msg, error) { return nil, nil }
26-
func (n NoopDA) BroadcastMsgs(nil btypes.ProcessedMsgs) {}
23+
func (n NoopDA) Start(_ context.Context) {}
24+
func (n NoopDA) HasKey() bool { return false }
25+
func (n NoopDA) CreateBatchMsg(_ []byte) (sdk.Msg, string, error) { return nil, "", nil }
26+
func (n NoopDA) BroadcastMsgs(nil btypes.ProcessedMsgs) {}
2727
func (n NoopDA) ProcessedMsgsToRawKV(_ []btypes.ProcessedMsgs, _ bool) ([]types.RawKV, error) {
2828
return nil, nil
2929
}

0 commit comments

Comments
 (0)