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

Assert finalization of Rollapp on Hub and decode SubmitFraudProposal #35

Open
wants to merge 4 commits into
base: v6
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ func (c *CosmosChain) ParamChangeProposal(ctx context.Context, keyName string, p
}

// SubmitFraudProposal submit a fraud proposal.
func (c *CosmosChain) SubmitFraudProposal(ctx context.Context, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit string) error {
_, err := c.getFullNode().SubmitFraudProposal(ctx, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit)
func (c *CosmosChain) SubmitFraudProposal(ctx context.Context, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit string) (tx TxProposal, _ error) {
txHash, err := c.getFullNode().SubmitFraudProposal(ctx, keyName, rollappChainID, height, proposerAddr, clientId, title, descrition, deposit)
if err != nil {
return fmt.Errorf("failed to submit fraud proposal: %w", err)
return tx, fmt.Errorf("failed to submit fraud proposal: %w", err)
}

return nil
return c.txProposal(txHash)
}

// QueryParam returns the param state of a given key.
Expand Down
29 changes: 27 additions & 2 deletions cosmos/hub/dym_hub/dym_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (c *DymHub) QueryRollappState(ctx context.Context,

var command []string
command = append(command, "rollapp", "state", rollappName)

if onlyFinalized {
command = append(command, "--finalized")
}
Expand All @@ -444,7 +444,7 @@ func (c *DymHub) QueryLatestStateIndex(ctx context.Context,
) (*dymension.QueryGetLatestStateIndexResponse, error) {
var command []string
command = append(command, "rollapp", "latest-state-index", rollappName)

if onlyFinalized {
command = append(command, "--finalized")
}
Expand Down Expand Up @@ -550,3 +550,28 @@ func (c *DymHub) WaitUntilRollappHeightIsFinalized(ctx context.Context, rollappC
}
}
}

func (c *DymHub) AssertFinalization(ctx context.Context, rollappName string, minIndex, timeoutSecs uint64) (bool, error) {

startTime := time.Now()
timeout := time.Duration(timeoutSecs) * time.Second

for {
select {
case <-time.After(timeout):
return false, fmt.Errorf("timeout reached without rollap state finalization index reach: %d", minIndex)
default:
latestFinalizedIndex, err := c.FinalizedRollappStateIndex(ctx, rollappName)
if err != nil {
if time.Since(startTime) < timeout {
time.Sleep(2 * time.Second) // 2sec interval
continue
}
}

if latestFinalizedIndex >= minIndex {
return true, nil
}
}
}
}