Skip to content

Commit

Permalink
refactor(hub client): improves hub client state query, and fixes tests (
Browse files Browse the repository at this point in the history
dymensionxyz#775)

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
danwt and github-actions authored May 3, 2024
1 parent 767b8fd commit b8fbe51
Show file tree
Hide file tree
Showing 38 changed files with 5,521 additions and 2,899 deletions.
24 changes: 24 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
with-expecter: true
recursive: true
packages:
github.com/dymensionxyz/dymint/settlement/dymension:
interfaces:
CosmosClient:
github.com/dymensionxyz/dymint/settlement:
interfaces:
LayerI:
HubClient:
github.com/tendermint/tendermint/abci/types:
interfaces:
Application:
github.com/tendermint/tendermint/proxy:
interfaces:
AppConnConsensus:
github.com/dymensionxyz/dymint/da/celestia/types:
interfaces:
CelestiaRPCClient:
github.com/dymensionxyz/dymint/da/avail:
interfaces:
SubstrateApiI:


1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Bug Fixes

* **bug:** sync from da and p2p when starting a node ([#763](https://github.com/dymensionxyz/dymint/issues/763)) ([68ffd05](https://github.com/dymensionxyz/dymint/commit/68ffd05794949ddc42df1c132d1fde5f21b505f4))
* **celestia test:** fix race in test ([#755](https://github.com/dymensionxyz/dymint/issues/755)) ([0b36781](https://github.com/dymensionxyz/dymint/commit/0b367818bf6aa8da4a4fd8e4e5c78223b60b44e0))
* **celestia:** impl retry on submit ([#748](https://github.com/dymensionxyz/dymint/issues/748)) ([61630eb](https://github.com/dymensionxyz/dymint/commit/61630eb458197abe2440a81426210000dff25d40))
* **celestia:** use fixed delay in repeat attempts ([#753](https://github.com/dymensionxyz/dymint/issues/753)) ([53002b0](https://github.com/dymensionxyz/dymint/commit/53002b0a070743811295a98580ba038cac40cc7d))
Expand Down
4 changes: 2 additions & 2 deletions block/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/dymensionxyz/dymint/mempool"
mempoolv1 "github.com/dymensionxyz/dymint/mempool/v1"
"github.com/dymensionxyz/dymint/mocks"
tmmocks "github.com/dymensionxyz/dymint/mocks/github.com/tendermint/tendermint/abci/types"
"github.com/dymensionxyz/dymint/types"
)

Expand Down Expand Up @@ -83,7 +83,7 @@ func TestApplyBlock(t *testing.T) {
logger := log.TestingLogger()

// Mock ABCI app
app := &mocks.Application{}
app := &tmmocks.MockApplication{}
app.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
app.On("BeginBlock", mock.Anything).Return(abci.ResponseBeginBlock{})
app.On("DeliverTx", mock.Anything).Return(abci.ResponseDeliverTx{})
Expand Down
30 changes: 13 additions & 17 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sync/atomic"
"time"

"github.com/dymensionxyz/dymint/gerr"

uevent "github.com/dymensionxyz/dymint/utils/event"

"code.cloudfoundry.org/go-diodes"
Expand Down Expand Up @@ -191,26 +193,25 @@ func (m *Manager) Start(ctx context.Context, isAggregator bool) error {

// syncBlockManager enforces the node to be synced on initial run.
func (m *Manager) syncBlockManager() error {
resultRetrieveBatch, err := m.getLatestBatchFromSL()
// Set the syncTarget according to the result
res, err := m.SLClient.RetrieveBatch()
if errors.Is(err, gerr.ErrNotFound) {
// The SL hasn't got any batches for this chain yet.
m.logger.Info("No batches for chain found in SL. Start writing first batch.")
m.SyncTarget.Store(uint64(m.Genesis.InitialHeight - 1))
return nil
}
if err != nil {
// TODO: separate between fresh rollapp and non-registered rollapp
if errors.Is(err, settlement.ErrBatchNotFound) {
// Since we requested the latest batch and got batch not found it means
// the SL still hasn't got any batches for this chain.
m.logger.Info("No batches for chain found in SL. Start writing first batch")
m.SyncTarget.Store(uint64(m.Genesis.InitialHeight - 1))
return nil
}
return err
}
m.SyncTarget.Store(resultRetrieveBatch.EndHeight)
err = m.syncUntilTarget(resultRetrieveBatch.EndHeight)
// Set the syncTarget according to the result
m.SyncTarget.Store(res.EndHeight)
err = m.syncUntilTarget(res.EndHeight)
if err != nil {
return err
}

m.logger.Info("Synced", "current height", m.Store.Height(), "syncTarget", m.SyncTarget.Load())
m.logger.Info("Synced.", "current height", m.Store.Height(), "syncTarget", m.SyncTarget.Load())
return nil
}

Expand Down Expand Up @@ -262,11 +263,6 @@ func (m *Manager) onNewGossipedBlock(event pubsub.Message) {
}
}

// getLatestBatchFromSL gets the latest batch from the SL
func (m *Manager) getLatestBatchFromSL() (*settlement.ResultRetrieveBatch, error) {
return m.SLClient.RetrieveBatch()
}

// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
func getInitialState(store store.Store, genesis *tmtypes.GenesisDoc, logger types.Logger) (types.State, error) {
s, err := store.LoadState()
Expand Down
5 changes: 2 additions & 3 deletions block/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"

"github.com/dymensionxyz/dymint/config"
mocks "github.com/dymensionxyz/dymint/mocks/settlement"
mocks "github.com/dymensionxyz/dymint/mocks/github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
)
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestBatchSubmissionFailedSubmission(t *testing.T) {
}

// Create a new mock LayerI
mockLayerI := &mocks.LayerI{}
mockLayerI := &mocks.MockLayerI{}
mockLayerI.On("Init", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
mockLayerI.On("Start").Return(nil)
mockLayerI.On("GetProposer").Return(proposer)
Expand Down Expand Up @@ -103,7 +103,6 @@ func TestBatchSubmissionFailedSubmission(t *testing.T) {
mockLayerI.On("SubmitBatch", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
manager.HandleSubmissionTrigger(ctx)
assert.EqualValues(t, 1, manager.SyncTarget.Load())

}

func TestBatchSubmissionAfterTimeout(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions da/avail/avail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
availtypes "github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/da/avail"
mocks "github.com/dymensionxyz/dymint/mocks/da/avail"
mocks "github.com/dymensionxyz/dymint/mocks/github.com/dymensionxyz/dymint/da/avail"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -123,7 +123,7 @@ func TestRetriveBatches(t *testing.T) {
})
require.NoError(err)
// Create mock client
mockSubstrateApiClient := mocks.NewSubstrateApiI(t)
mockSubstrateApiClient := mocks.NewMockSubstrateApiI(t)
// Configure DALC options
options := []da.Option{
avail.WithClient(mockSubstrateApiClient),
Expand Down
6 changes: 3 additions & 3 deletions da/celestia/celestia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/tendermint/tendermint/libs/log"

mocks "github.com/dymensionxyz/dymint/mocks/da/celestia"
mocks "github.com/dymensionxyz/dymint/mocks/github.com/dymensionxyz/dymint/da/celestia/types"

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/da/celestia"
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestRetrievalWrongCommitment(t *testing.T) {
assert.ErrorIs(availRes.Error, da.ErrUnableToGetProof)
}

func setDAandMock(t *testing.T) (*mocks.CelestiaRPCClient, da.DataAvailabilityLayerClient, []byte, *header.ExtendedHeader) {
func setDAandMock(t *testing.T) (*mocks.MockCelestiaRPCClient, da.DataAvailabilityLayerClient, []byte, *header.ExtendedHeader) {
var err error
pubsubServer := pubsub.NewServer()
err = pubsubServer.Start()
Expand All @@ -311,7 +311,7 @@ func setDAandMock(t *testing.T) (*mocks.CelestiaRPCClient, da.DataAvailabilityLa
conf, err := json.Marshal(config)
require.NoError(err)

mockRPCClient := mocks.NewCelestiaRPCClient(t)
mockRPCClient := mocks.NewMockCelestiaRPCClient(t)
options := []da.Option{
celestia.WithRPCClient(mockRPCClient),
celestia.WithRPCAttempts(1),
Expand Down
4 changes: 2 additions & 2 deletions da/celestia/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/da/celestia"
mocks "github.com/dymensionxyz/dymint/mocks/da/celestia"
mocks "github.com/dymensionxyz/dymint/mocks/github.com/dymensionxyz/dymint/da/celestia/types"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types"
"github.com/rollkit/celestia-openrpc/types/blob"
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestSubmitBatch(t *testing.T) {

t.Log("Case name ", tc.name)
// Create mock clients
mockRPCClient := mocks.NewCelestiaRPCClient(t)
mockRPCClient := mocks.NewMockCelestiaRPCClient(t)
// Configure DALC options
options := []da.Option{
celestia.WithSubmitBackoff(uretry.NewBackoffConfig(uretry.WithInitialDelay(10*time.Millisecond), uretry.WithMaxDelay(10*time.Millisecond))),
Expand Down
2 changes: 2 additions & 0 deletions mockery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package mockery .. this is required by mockery, see https://vektra.github.io/mockery/latest/notes/#error-no-go-files-found-in-root-search-path
package mockery
195 changes: 0 additions & 195 deletions mocks/Application.go

This file was deleted.

Loading

0 comments on commit b8fbe51

Please sign in to comment.