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/split oracletx #45

Merged
merged 26 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6808dc8
find tx using txsearch with tx hash
sh-cha Nov 15, 2024
3c09977
change sequence
sh-cha Nov 15, 2024
bbc8c22
add oracle executor account to avoid executor sequence mismatch
sh-cha Nov 18, 2024
d83f440
query block header instead of block
sh-cha Nov 18, 2024
617d34e
handle tx failed
sh-cha Nov 18, 2024
6520ab4
remove redunt sequence err
sh-cha Nov 18, 2024
1b6b3e9
Merge branch 'main' into fix/tx-checker
sh-cha Nov 18, 2024
9f09908
Merge branch 'fix/tx-checker' into feat/split-oracletx
sh-cha Nov 18, 2024
3836f25
update readme
sh-cha Nov 18, 2024
428ff5c
return sender when creating msgs & split msg queue every sender
sh-cha Nov 18, 2024
d929e38
set bridge info first
sh-cha Nov 18, 2024
18427c0
update authz grant checker
sh-cha Nov 18, 2024
4e3e84b
add sender
sh-cha Nov 18, 2024
5552d0b
add broadcaster account checker
sh-cha Nov 18, 2024
95317d6
sender not set bug fix
sh-cha Nov 18, 2024
a2185ab
delete debug print
sh-cha Nov 18, 2024
227785f
add sender to pendingtx
sh-cha Nov 18, 2024
a0131cb
add sender when unmarshalling processed msgs
sh-cha Nov 18, 2024
9ef04b2
remove redundant msg queue allocation
sh-cha Nov 18, 2024
8a88763
Merge branch 'main' into feat/split-oracletx
sh-cha Nov 18, 2024
8b1daff
format
sh-cha Nov 18, 2024
bded342
delete processed msgs from db when simulation failed and error is han…
sh-cha Nov 18, 2024
d22889e
change oracle tx sender
sh-cha Nov 18, 2024
3ec9bfd
change proof query error (#46)
sh-cha Nov 18, 2024
3d0d21c
enable to query withdrawals that their tree is not finalized yet (#47)
sh-cha Nov 19, 2024
0abbac7
introduce authz tx msg command (#48)
sh-cha Nov 19, 2024
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
9 changes: 7 additions & 2 deletions challenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ To configure the Challenger, fill in the values in the `~/.opinit/challenger.jso
// Version is the version used to build output root.
// Please refer to `spec_version.json` for the correct version for each network.
"version": 1,
// ListenAddress is the address to listen for incoming requests.
"listen_address": "localhost:3001",
// Server is the configuration for the server.
"server": {
"address": "localhost:3000",
"allow_origins": "*",
"allow_headers": "Origin, Content-Type, Accept",
"allow_methods": "GET",
},
"l1_node": {
"chain_id": "testnet-l1-1",
"bech32_prefix": "init",
Expand Down
2 changes: 1 addition & 1 deletion challenger/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewChildV1(
}

func (ch *Child) Initialize(ctx context.Context, processedHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo ophosttypes.QueryBridgeResponse, challenger challenger) (time.Time, error) {
_, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, nil)
_, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, nil, nil)
if err != nil {
return time.Time{}, err
}
Expand Down
14 changes: 12 additions & 2 deletions executor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
// Version is the version used to build output root.
// Please refer to `spec_version.json` for the correct version for each network.
"version": 1,
// ListenAddress is the address to listen for incoming requests.
"listen_address": "localhost:3000",
// Server is the configuration for the server.
"server": {
"address": "localhost:3000",
"allow_origins": "*",
"allow_headers": "Origin, Content-Type, Accept",
"allow_methods": "GET",
},
"l1_node": {
"chain_id": "testnet-l1-1",
"bech32_prefix": "init",
Expand Down Expand Up @@ -47,6 +52,11 @@ To configure the Executor, fill in the values in the `~/.opinit/executor.json` f
//
// If you don't want to use the bridge executor feature, you can leave it empty.
"bridge_executor": "",
// OracleBridgeExecutor is the key name in the keyring for the oracle bridge executor,
// which is used to relay oracle transaction from l1 to l2.
//
// If L2 is using oracle, you need to set this field.
"oracle_bridge_executor": "",

// DisableOutputSubmitter is the flag to disable the output submitter.
// If it is true, the output submitter will not be started.
Expand Down
6 changes: 4 additions & 2 deletions executor/batch/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,12 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight int64)
checksums,
)

msg, err := bs.da.CreateBatchMsg(headerData)
msg, sender, err := bs.da.CreateBatchMsg(headerData)
if err != nil {
return err
} else if msg != nil {
bs.processedMsgs = append(bs.processedMsgs, btypes.ProcessedMsgs{
Sender: sender,
Msgs: []sdk.Msg{msg},
Timestamp: time.Now().UnixNano(),
Save: true,
Expand All @@ -220,11 +221,12 @@ func (bs *BatchSubmitter) finalizeBatch(ctx context.Context, blockHeight int64)
types.MustInt64ToUint64(int64(len(checksums))),
chunk,
)
msg, err := bs.da.CreateBatchMsg(chunkData)
msg, sender, err := bs.da.CreateBatchMsg(chunkData)
if err != nil {
return err
} else if msg != nil {
bs.processedMsgs = append(bs.processedMsgs, btypes.ProcessedMsgs{
Sender: sender,
Msgs: []sdk.Msg{msg},
Timestamp: time.Now().UnixNano(),
Save: true,
Expand Down
8 changes: 4 additions & 4 deletions executor/batch/noop_da.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func NewNoopDA() *NoopDA {
return &NoopDA{}
}

func (n NoopDA) Start(_ context.Context) {}
func (n NoopDA) HasKey() bool { return false }
func (n NoopDA) CreateBatchMsg(_ []byte) (sdk.Msg, error) { return nil, nil }
func (n NoopDA) BroadcastMsgs(nil btypes.ProcessedMsgs) {}
func (n NoopDA) Start(_ context.Context) {}
func (n NoopDA) HasKey() bool { return false }
func (n NoopDA) CreateBatchMsg(_ []byte) (sdk.Msg, string, error) { return nil, "", nil }
func (n NoopDA) BroadcastMsgs(nil btypes.ProcessedMsgs) {}
func (n NoopDA) ProcessedMsgsToRawKV(_ []btypes.ProcessedMsgs, _ bool) ([]types.RawKV, error) {
return nil, nil
}
Expand Down
85 changes: 18 additions & 67 deletions executor/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import (

"go.uber.org/zap"

"github.com/cometbft/cometbft/crypto/merkle"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"

inclusion "github.com/celestiaorg/go-square/v2/inclusion"
sh "github.com/celestiaorg/go-square/v2/share"

executortypes "github.com/initia-labs/opinit-bots/executor/types"
Expand Down Expand Up @@ -45,9 +41,6 @@ type Celestia struct {
cfg nodetypes.NodeConfig
db types.DB
logger *zap.Logger

processedMsgs []btypes.ProcessedMsgs
msgQueue []sdk.Msg
}

func NewDACelestia(
Expand All @@ -60,21 +53,13 @@ func NewDACelestia(
cfg: cfg,
db: db,
logger: logger,

processedMsgs: make([]btypes.ProcessedMsgs, 0),
msgQueue: make([]sdk.Msg, 0),
}

appCodec, txConfig, err := createCodec(cfg.Bech32Prefix)
if err != nil {
panic(err)
}

if cfg.BroadcasterConfig != nil {
cfg.BroadcasterConfig.BuildTxWithMessages = c.BuildTxWithMessages
cfg.BroadcasterConfig.PendingTxToProcessedMsgs = c.PendingTxToProcessedMsgs
}

node, err := node.NewNode(cfg, db, logger, appCodec, txConfig)
if err != nil {
panic(err)
Expand All @@ -95,7 +80,7 @@ func createCodec(bech32Prefix string) (codec.Codec, client.TxConfig, error) {
}

func (c *Celestia) Initialize(ctx context.Context, batch batchNode, bridgeId uint64, keyringConfig *btypes.KeyringConfig) error {
err := c.node.Initialize(ctx, 0, keyringConfig)
err := c.node.Initialize(ctx, 0, c.keyringConfigs(keyringConfig))
if err != nil {
return err
}
Expand Down Expand Up @@ -142,66 +127,32 @@ func (c Celestia) GetHeight() int64 {
return c.node.GetHeight()
}

func (c Celestia) CreateBatchMsg(rawBlob []byte) (sdk.Msg, error) {
submitter, err := c.GetAddressStr()
if err != nil {
if errors.Is(err, types.ErrKeyNotSet) {
return nil, nil
}
return nil, err
}
blob, err := sh.NewV0Blob(c.namespace, rawBlob)
if err != nil {
return nil, err
}
commitment, err := inclusion.CreateCommitment(blob,
merkle.HashFromByteSlices,
// https://github.com/celestiaorg/celestia-app/blob/4f4d0f7ff1a43b62b232726e52d1793616423df7/pkg/appconsts/v1/app_consts.go#L6
64,
)
if err != nil {
return nil, err
}

dataLength, err := types.SafeIntToUint32(len(blob.Data()))
if err != nil {
return nil, err
}

return &celestiatypes.MsgPayForBlobsWithBlob{
MsgPayForBlobs: &celestiatypes.MsgPayForBlobs{
Signer: submitter,
Namespaces: [][]byte{c.namespace.Bytes()},
ShareCommitments: [][]byte{commitment},
BlobSizes: []uint32{dataLength},
ShareVersions: []uint32{uint32(blob.ShareVersion())},
},
Blob: &celestiatypes.Blob{
NamespaceId: blob.Namespace().ID(),
Data: blob.Data(),
ShareVersion: uint32(blob.ShareVersion()),
NamespaceVersion: uint32(blob.Namespace().Version()),
},
}, nil
}

func (c Celestia) NamespaceID() []byte {
chainIDhash := sha256.Sum256([]byte(c.batch.ChainID()))
return chainIDhash[:10]
}

func (c Celestia) GetAddress() (sdk.AccAddress, error) {
func (c Celestia) BaseAccountAddress() (string, error) {
broadcaster, err := c.node.GetBroadcaster()
if err != nil {
return nil, err
if errors.Is(err, types.ErrKeyNotSet) {
return "", nil
}
return "", err
}
account, err := broadcaster.AccountByIndex(0)
if err != nil {
return "", err
}
return broadcaster.GetAddress(), nil

sender := account.GetAddressString()
return sender, nil
}

func (c Celestia) GetAddressStr() (string, error) {
broadcaster, err := c.node.GetBroadcaster()
if err != nil {
return "", err
func (c Celestia) keyringConfigs(baseConfig *btypes.KeyringConfig) []btypes.KeyringConfig {
var configs []btypes.KeyringConfig
if baseConfig != nil {
configs = append(configs, *baseConfig)
}
return broadcaster.GetAddressString()
return configs
}
58 changes: 58 additions & 0 deletions executor/celestia/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package celestia

import (
"errors"

"github.com/cometbft/cometbft/crypto/merkle"

sdk "github.com/cosmos/cosmos-sdk/types"

inclusion "github.com/celestiaorg/go-square/v2/inclusion"
sh "github.com/celestiaorg/go-square/v2/share"

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

func (c Celestia) CreateBatchMsg(rawBlob []byte) (sdk.Msg, string, error) {
submitter, err := c.BaseAccountAddress()
if err != nil {
if errors.Is(err, types.ErrKeyNotSet) {
return nil, "", nil
}
return nil, "", err
}
blob, err := sh.NewV0Blob(c.namespace, rawBlob)
if err != nil {
return nil, "", err
}
commitment, err := inclusion.CreateCommitment(blob,
merkle.HashFromByteSlices,
// https://github.com/celestiaorg/celestia-app/blob/4f4d0f7ff1a43b62b232726e52d1793616423df7/pkg/appconsts/v1/app_consts.go#L6
64,
)
if err != nil {
return nil, "", err
}

dataLength, err := types.SafeIntToUint32(len(blob.Data()))
if err != nil {
return nil, "", err
}

return &celestiatypes.MsgPayForBlobsWithBlob{
MsgPayForBlobs: &celestiatypes.MsgPayForBlobs{
Signer: submitter,
Namespaces: [][]byte{c.namespace.Bytes()},
ShareCommitments: [][]byte{commitment},
BlobSizes: []uint32{dataLength},
ShareVersions: []uint32{uint32(blob.ShareVersion())},
},
Blob: &celestiatypes.Blob{
NamespaceId: blob.Namespace().ID(),
Data: blob.Data(),
ShareVersion: uint32(blob.ShareVersion()),
NamespaceVersion: uint32(blob.Namespace().Version()),
},
}, submitter, nil
}
16 changes: 2 additions & 14 deletions executor/celestia/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"

btypes "github.com/initia-labs/opinit-bots/node/broadcaster/types"
Expand Down Expand Up @@ -34,25 +33,14 @@ func (c *Celestia) BuildTxWithMessages(
blobMsgs = append(blobMsgs, withBlobMsg.Blob)
}

b := c.node.MustGetBroadcaster()
txf := b.GetTxf()

_, adjusted, err := b.CalculateGas(ctx, txf, pfbMsgs...)
broadcasterAccount, err := c.node.MustGetBroadcaster().AccountByIndex(0)
if err != nil {
return nil, "", err
}

txf = txf.WithGas(adjusted)
txb, err := txf.BuildUnsignedTx(pfbMsgs...)
tx, err := broadcasterAccount.SimulateAndSignTx(ctx, pfbMsgs...)
if err != nil {
return nil, "", err
}

if err = tx.Sign(ctx, txf, b.KeyName(), txb, false); err != nil {
return nil, "", err
}

tx := txb.GetTx()
txConfig := c.node.GetTxConfig()
txBytes, err = txutils.EncodeTx(txConfig, tx)
if err != nil {
Expand Down
16 changes: 12 additions & 4 deletions executor/child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
)

type hostNode interface {
GetAddressStr() (string, error)
HasKey() bool
BaseAccountAddressString() (string, error)
BroadcastMsgs(btypes.ProcessedMsgs)
ProcessedMsgsToRawKV([]btypes.ProcessedMsgs, bool) ([]types.RawKV, error)
QueryLastOutput(context.Context, uint64) (*ophosttypes.QueryOutputProposalResponse, error)
QueryOutput(context.Context, uint64, uint64, int64) (*ophosttypes.QueryOutputProposalResponse, error)

GetMsgProposeOutput(uint64, uint64, int64, []byte) (sdk.Msg, error)
GetMsgProposeOutput(uint64, uint64, int64, []byte) (sdk.Msg, string, error)
}

type Child struct {
Expand Down Expand Up @@ -58,8 +58,16 @@ func NewChildV1(
}
}

func (ch *Child) Initialize(ctx context.Context, processedHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo ophosttypes.QueryBridgeResponse, keyringConfig *btypes.KeyringConfig) error {
l2Sequence, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, keyringConfig)
func (ch *Child) Initialize(
ctx context.Context,
processedHeight int64,
startOutputIndex uint64,
host hostNode,
bridgeInfo ophosttypes.QueryBridgeResponse,
keyringConfig *btypes.KeyringConfig,
oracleKeyringConfig *btypes.KeyringConfig,
) error {
l2Sequence, err := ch.BaseChild.Initialize(ctx, processedHeight, startOutputIndex, bridgeInfo, keyringConfig, oracleKeyringConfig)
if err != nil {
return err
}
Expand Down
Loading
Loading