Skip to content

Commit

Permalink
send revision
Browse files Browse the repository at this point in the history
  • Loading branch information
Faulty Tolly committed Nov 7, 2024
1 parent ba0b57c commit 98ee90a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 32 deletions.
8 changes: 4 additions & 4 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
assert.NoError(t, err)
daResultSubmitBatch := manager.DAClient.SubmitBatch(batch)
assert.Equal(t, daResultSubmitBatch.Code, da.StatusSuccess)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch, 0)
require.NoError(t, err)
nextBatchStartHeight = batch.EndHeight() + 1
lastBlockHeaderHash = batch.Blocks[len(batch.Blocks)-1].Header.Hash()
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestApplyLocalBlock_WithFraudCheck(t *testing.T) {
daResultSubmitBatch := manager.DAClient.SubmitBatch(batch)
assert.Equal(t, daResultSubmitBatch.Code, da.StatusSuccess)

err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch, 0)
require.NoError(t, err)

nextBatchStartHeight = batch.EndHeight() + 1
Expand Down Expand Up @@ -714,7 +714,7 @@ func TestDAFetch(t *testing.T) {
require.NoError(err)
daResultSubmitBatch := manager.DAClient.SubmitBatch(batch)
require.Equal(daResultSubmitBatch.Code, da.StatusSuccess)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch, 0)
require.NoError(err)

cases := []struct {
Expand Down Expand Up @@ -807,7 +807,7 @@ func TestManager_ApplyBatchFromSL_FraudHandling(t *testing.T) {
require.NoError(err)
daResultSubmitBatch := manager.DAClient.SubmitBatch(batch)
require.Equal(daResultSubmitBatch.Code, da.StatusSuccess)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch)
err = manager.SLClient.SubmitBatch(batch, manager.DAClient.GetClientType(), &daResultSubmitBatch, 0)
require.NoError(err)

// Mock Executor to return ErrFraud
Expand Down
4 changes: 3 additions & 1 deletion block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ func (m *Manager) SubmitBatch(batch *types.Batch) error {
}
m.logger.Info("Submitted batch to DA.", "start height", batch.StartHeight(), "end height", batch.EndHeight())

err := m.SLClient.SubmitBatch(batch, m.DAClient.GetClientType(), &resultSubmitToDA)
revision := m.State.Version.Consensus.App

err := m.SLClient.SubmitBatch(batch, m.DAClient.GetClientType(), &resultSubmitToDA, revision)
if err != nil {
return fmt.Errorf("sl client submit batch: start height: %d: end height: %d: %w", batch.StartHeight(), batch.EndHeight(), err)
}
Expand Down
21 changes: 11 additions & 10 deletions mocks/github.com/dymensionxyz/dymint/settlement/mock_ClientI.go

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

21 changes: 11 additions & 10 deletions settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func (c *Client) Stop() error {

// SubmitBatch posts a batch to the Dymension Hub. it tries to post the batch until it is accepted by the settlement layer.
// it emits success and failure events to the event bus accordingly.
func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch) error {
msgUpdateState, err := c.convertBatchToMsgUpdateState(batch, daResult)
func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch, revision uint64) error {
msgUpdateState, err := c.convertBatchToMsgUpdateState(batch, daResult, revision)
if err != nil {
return fmt.Errorf("convert batch to msg update state: %w", err)
}
Expand Down Expand Up @@ -606,7 +606,7 @@ func (c *Client) broadcastBatch(msgUpdateState *rollapptypes.MsgUpdateState) err
return nil
}

func (c *Client) convertBatchToMsgUpdateState(batch *types.Batch, daResult *da.ResultSubmitBatch) (*rollapptypes.MsgUpdateState, error) {
func (c *Client) convertBatchToMsgUpdateState(batch *types.Batch, daResult *da.ResultSubmitBatch, rollappRevision uint64) (*rollapptypes.MsgUpdateState, error) {
account, err := c.cosmosClient.GetAccount(c.config.DymAccountName)
if err != nil {
return nil, fmt.Errorf("get account: %w", err)
Expand All @@ -629,13 +629,14 @@ func (c *Client) convertBatchToMsgUpdateState(batch *types.Batch, daResult *da.R
}

settlementBatch := &rollapptypes.MsgUpdateState{
Creator: addr,
RollappId: c.rollappId,
StartHeight: batch.StartHeight(),
NumBlocks: batch.NumBlocks(),
DAPath: daResult.SubmitMetaData.ToPath(),
BDs: rollapptypes.BlockDescriptors{BD: blockDescriptors},
Last: batch.LastBatch,
Creator: addr,
RollappId: c.rollappId,
StartHeight: batch.StartHeight(),
NumBlocks: batch.NumBlocks(),
DAPath: daResult.SubmitMetaData.ToPath(),
BDs: rollapptypes.BlockDescriptors{BD: blockDescriptors},
Last: batch.LastBatch,
RollappRevision: rollappRevision,
}
return settlementBatch, nil
}
Expand Down
2 changes: 1 addition & 1 deletion settlement/dymension/dymension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestPostBatch(t *testing.T) {
errChan := make(chan error, 1) // Create a channel to receive an error from the goroutine
// Post the batch in a goroutine and capture any error.
go func() {
err := hubClient.SubmitBatch(batch, da.Mock, resultSubmitBatch)
err := hubClient.SubmitBatch(batch, da.Mock, resultSubmitBatch, 0)
errChan <- err // Send any error to the errChan
}()

Expand Down
2 changes: 1 addition & 1 deletion settlement/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *Client) Stop() error {
}

// SubmitBatch saves the batch to the kv store
func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch) error {
func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch, revision uint64) error {
settlementBatch := c.convertBatchtoSettlementBatch(batch, daResult)
err := c.saveBatch(settlementBatch)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion settlement/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *Client) Stop() error {
}

// PostBatch saves the batch to the kv store
func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch) error {
func (c *Client) SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch, revision uint64) error {
settlementBatch := c.convertBatchToSettlementBatch(batch, daResult)
err := c.saveBatch(settlementBatch)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions settlement/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestSubmitBatch(t *testing.T) {
resultSubmitBatch.SubmitMetaData = &da.DASubmitMetaData{}

// Submit the first batch and check if it was successful
err = sllayer.SubmitBatch(batch1, da.Mock, resultSubmitBatch)
err = sllayer.SubmitBatch(batch1, da.Mock, resultSubmitBatch, 0)
assert.NoError(err)
assert.True(resultSubmitBatch.Code == 0) // success code

Expand All @@ -86,7 +86,7 @@ func TestSubmitBatch(t *testing.T) {
assert.Equal(batch1.EndHeight(), queriedBatch.Batch.EndHeight)

// Submit the 2nd batch and check if it was successful
err = sllayer.SubmitBatch(batch2, da.Mock, resultSubmitBatch)
err = sllayer.SubmitBatch(batch2, da.Mock, resultSubmitBatch, 0)
assert.NoError(err)
assert.True(resultSubmitBatch.Code == 0) // success code

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestPersistency(t *testing.T) {
resultSubmitBatch.SubmitMetaData = &da.DASubmitMetaData{}

// Submit the first batch and check if it was successful
err = sllayer.SubmitBatch(batch1, da.Mock, resultSubmitBatch)
err = sllayer.SubmitBatch(batch1, da.Mock, resultSubmitBatch, 0)
assert.NoError(err)
assert.True(resultSubmitBatch.Code == 0) // success code

Expand Down
2 changes: 1 addition & 1 deletion settlement/settlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type ClientI interface {
Stop() error
// SubmitBatch tries submitting the batch in an async way to the settlement layer. This should create a transaction which (potentially)
// triggers a state transition in the settlement layer. Events are emitted on success or failure.
SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch) error
SubmitBatch(batch *types.Batch, daClient da.Client, daResult *da.ResultSubmitBatch, revision uint64) error
// GetLatestBatch returns the latest batch from the settlement layer.
GetLatestBatch() (*ResultRetrieveBatch, error)
// GetBatchAtIndex returns the batch at the given index.
Expand Down

0 comments on commit 98ee90a

Please sign in to comment.