Skip to content
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ enum SupernodeEventType {
SIGNATURE_VERIFIED = 7;
RQID_GENERATED = 8;
RQID_VERIFIED = 9;
ARTEFACTS_STORED = 10;
ACTION_FINALIZED = 11;
ARTEFACTS_DOWNLOADED = 12;
FINALIZE_SIMULATED = 10;
ARTEFACTS_STORED = 11;
ACTION_FINALIZED = 12;
ARTEFACTS_DOWNLOADED = 13;
}
```

Expand Down
70 changes: 38 additions & 32 deletions gen/supernode/action/cascade/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pkg/lumera/Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Lumera Client (Slim Guide)
## Lumera Client

A minimal guide to the Lumera client

Expand Down Expand Up @@ -47,7 +47,7 @@ Send actions (ActionMsg)
RequestAction:

```go
resp, err := cli.ActionMsg().RequesAction(
resp, err := cli.ActionMsg().RequestAction(
ctx,
"CASCADE",
metadataJSON, // stringified JSON
Expand All @@ -73,5 +73,4 @@ Validation rules (built-in)

Notes

- Method name is currently `RequesAction` (typo kept for compatibility).
- Tx uses simulation + adjustment + padding before sign/broadcast.
27 changes: 21 additions & 6 deletions pkg/lumera/modules/action_msg/action_msg_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion pkg/lumera/modules/action_msg/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newModule(conn *grpc.ClientConn, authmodule auth.Module, txmodule txmod.Mod
}, nil
}

func (m *module) RequesAction(ctx context.Context, actionType, metadata, price, expirationTime string) (*sdktx.BroadcastTxResponse, error) {
func (m *module) RequestAction(ctx context.Context, actionType, metadata, price, expirationTime string) (*sdktx.BroadcastTxResponse, error) {
if err := validateRequestActionParams(actionType, metadata, price, expirationTime); err != nil {
return nil, err
}
Expand Down Expand Up @@ -74,3 +74,31 @@ func (m *module) SetTxHelperConfig(config *txmod.TxHelperConfig) {
func (m *module) GetTxHelper() *txmod.TxHelper {
return m.txHelper
}

// SimulateFinalizeCascadeAction builds the finalize message and performs a simulation
// without broadcasting the transaction. This is useful to ensure the transaction
// would pass ante/ValidateBasic before doing irreversible work.
func (m *module) SimulateFinalizeCascadeAction(ctx context.Context, actionId string, rqIdsIds []string) (*sdktx.SimulateResponse, error) {
if err := validateFinalizeActionParams(actionId, rqIdsIds); err != nil {
return nil, err
}

// Gather account info and creator address
accountInfo, err := m.txHelper.GetAccountInfo(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get account info: %w", err)
}
creator, err := m.txHelper.GetCreatorAddress()
if err != nil {
return nil, fmt.Errorf("failed to get creator address: %w", err)
}

// Build the finalize message
msg, err := createFinalizeActionMessage(creator, actionId, rqIdsIds)
if err != nil {
return nil, err
}

// Run simulation using tx helper
return m.txHelper.Simulate(ctx, []types.Msg{msg}, accountInfo)
}
4 changes: 3 additions & 1 deletion pkg/lumera/modules/action_msg/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (

type Module interface {
// FinalizeCascadeAction finalizes a CASCADE action with the given parameters
RequesAction(ctx context.Context, actionType, metadata, price, expirationTime string) (*sdktx.BroadcastTxResponse, error)
RequestAction(ctx context.Context, actionType, metadata, price, expirationTime string) (*sdktx.BroadcastTxResponse, error)
FinalizeCascadeAction(ctx context.Context, actionId string, rqIdsIds []string) (*sdktx.BroadcastTxResponse, error)
// SimulateFinalizeCascadeAction simulates the finalize action (no broadcast)
SimulateFinalizeCascadeAction(ctx context.Context, actionId string, rqIdsIds []string) (*sdktx.SimulateResponse, error)
}

func NewModule(conn *grpc.ClientConn, authmod auth.Module, txmodule tx.Module, kr keyring.Keyring, keyName string, chainID string) (Module, error) {
Expand Down
80 changes: 43 additions & 37 deletions pkg/lumera/modules/tx/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,46 +135,52 @@ func (h *TxHelper) GetAccountInfo(ctx context.Context) (*authtypes.BaseAccount,

// UpdateConfig allows updating the transaction configuration
func (h *TxHelper) UpdateConfig(config *TxHelperConfig) {
// Merge provided fields with existing config to avoid zeroing defaults
if h.config == nil {
h.config = &TxConfig{}
}

// ChainID
if config.ChainID != "" {
h.config.ChainID = config.ChainID
}
// Keyring
if config.Keyring != nil {
h.config.Keyring = config.Keyring
}
// KeyName
if config.KeyName != "" {
h.config.KeyName = config.KeyName
}
// GasLimit
if config.GasLimit != 0 {
h.config.GasLimit = config.GasLimit
}
// GasAdjustment
if config.GasAdjustment != 0 {
h.config.GasAdjustment = config.GasAdjustment
}
// GasPadding
if config.GasPadding != 0 {
h.config.GasPadding = config.GasPadding
}
// FeeDenom
if config.FeeDenom != "" {
h.config.FeeDenom = config.FeeDenom
}
// GasPrice
if config.GasPrice != "" {
h.config.GasPrice = config.GasPrice
}
// Merge provided fields with existing config to avoid zeroing defaults
if h.config == nil {
h.config = &TxConfig{}
}

// ChainID
if config.ChainID != "" {
h.config.ChainID = config.ChainID
}
// Keyring
if config.Keyring != nil {
h.config.Keyring = config.Keyring
}
// KeyName
if config.KeyName != "" {
h.config.KeyName = config.KeyName
}
// GasLimit
if config.GasLimit != 0 {
h.config.GasLimit = config.GasLimit
}
// GasAdjustment
if config.GasAdjustment != 0 {
h.config.GasAdjustment = config.GasAdjustment
}
// GasPadding
if config.GasPadding != 0 {
h.config.GasPadding = config.GasPadding
}
// FeeDenom
if config.FeeDenom != "" {
h.config.FeeDenom = config.FeeDenom
}
// GasPrice
if config.GasPrice != "" {
h.config.GasPrice = config.GasPrice
}
}

// GetConfig returns the current transaction configuration
func (h *TxHelper) GetConfig() *TxConfig {
return h.config
}

// Simulate runs an offline simulation for the provided messages using the
// configured tx settings and given account info. Useful for pre-flight checks.
func (h *TxHelper) Simulate(ctx context.Context, msgs []types.Msg, accountInfo *authtypes.BaseAccount) (*sdktx.SimulateResponse, error) {
return h.txmod.SimulateTransaction(ctx, msgs, accountInfo, h.config)
}
19 changes: 9 additions & 10 deletions pkg/testutil/lumera.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,9 @@ func (m *MockActionModule) GetParams(ctx context.Context) (*types.QueryParamsRes
type MockActionMsgModule struct{}

// RequestAction mocks the behavior of requesting an action.
// Adjust the signature and return values as needed to match the actual interface.
func (m *MockActionMsgModule) RequestAction(ctx context.Context, req *types.MsgRequestAction) (*sdktx.BroadcastTxResponse, error) {
// Mock implementation returns success with empty result
return &sdktx.BroadcastTxResponse{}, nil
}

// RequesAction is a stub to satisfy the action_msg.Module interface in case of typo in interface definition.
func (m *MockActionMsgModule) RequesAction(ctx context.Context, arg1, arg2, arg3, arg4 string) (*sdktx.BroadcastTxResponse, error) {
// Mock implementation returns success with empty result
return &sdktx.BroadcastTxResponse{}, nil
func (m *MockActionMsgModule) RequestAction(ctx context.Context, actionType, metadata, price, expirationTime string) (*sdktx.BroadcastTxResponse, error) {
// Mock implementation returns success with empty result
return &sdktx.BroadcastTxResponse{}, nil
}

// FinalizeCascadeAction implements the required method from action_msg.Module interface
Expand All @@ -141,6 +134,12 @@ func (m *MockActionMsgModule) FinalizeCascadeAction(ctx context.Context, actionI
return &sdktx.BroadcastTxResponse{}, nil
}

// SimulateFinalizeCascadeAction mocks simulation of finalize action.
func (m *MockActionMsgModule) SimulateFinalizeCascadeAction(ctx context.Context, actionId string, signatures []string) (*sdktx.SimulateResponse, error) {
// Mock implementation returns empty simulation response
return &sdktx.SimulateResponse{}, nil
}

// MockSupernodeModule implements the supernode.Module interface for testing
type MockSupernodeModule struct {
addresses []string
Expand Down
8 changes: 4 additions & 4 deletions proto/supernode/action/cascade/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ enum SupernodeEventType {
SIGNATURE_VERIFIED = 7;
RQID_GENERATED = 8;
RQID_VERIFIED = 9;
ARTEFACTS_STORED = 10;
ACTION_FINALIZED = 11;
ARTEFACTS_DOWNLOADED = 12;
FINALIZE_SIMULATED = 10;
ARTEFACTS_STORED = 11;
ACTION_FINALIZED = 12;
ARTEFACTS_DOWNLOADED = 13;
}

4 changes: 3 additions & 1 deletion sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,14 @@ The SDK provides an event system to monitor task progress through event subscrip
- `SupernodeSignatureVerified`: Signature verification passed
- `SupernodeRQIDGenerated`: RaptorQ ID generated
- `SupernodeRQIDVerified`: RaptorQ ID verified
- `SupernodeFinalizeSimulated`: Finalize transaction simulated successfully (pre-storage)
- `SupernodeArtefactsStored`: Artifacts stored successfully
- `SupernodeActionFinalized`: Action processing finalized
- `SupernodeArtefactsDownloaded`: Artifacts downloaded
- `SupernodeUnknown`: Unknown supernode event

Note: For backward compatibility, older supernodes may emit the finalize simulation as an `RQID_VERIFIED` event with the message `"finalize action simulation passed"`. The SDK adapter maps this to `SupernodeFinalizeSimulated` automatically.

### Event Data Keys

Events may include additional data accessible through these keys:
Expand Down Expand Up @@ -415,4 +418,3 @@ err := client.SubscribeToEvents(ctx, event.SDKTaskCompleted, func(ctx context.Co
err := client.SubscribeToAllEvents(ctx, func(ctx context.Context, e event.Event) {
fmt.Printf("Event: %s for task %s\n", e.Type, e.TaskID)
})

Loading