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

fix(code standards): fmt and fumpt #685

Merged
merged 1 commit into from
Apr 15, 2024
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
1 change: 0 additions & 1 deletion block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,4 @@ func (m *Manager) gossipBlock(ctx context.Context, block types.Block, commit typ
return err
}
return nil

}
6 changes: 3 additions & 3 deletions block/initchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import (
)

func (m *Manager) RunInitChain(ctx context.Context) error {
//get the proposer's consensus pubkey
// get the proposer's consensus pubkey
proposer := m.settlementClient.GetProposer()
tmPubKey, err := cryptocodec.ToTmPubKeyInterface(proposer.PublicKey)
if err != nil {
return err
}
gensisValSet := []*tmtypes.Validator{tmtypes.NewValidator(tmPubKey, 1)}

//call initChain with both addresses
// call initChain with both addresses
res, err := m.executor.InitChain(m.genesis, gensisValSet)
if err != nil {
return err
}

//update the state with only the consensus pubkey
// update the state with only the consensus pubkey
m.executor.UpdateStateAfterInitChain(&m.lastState, res, gensisValSet)
if _, err := m.store.UpdateState(m.lastState, nil); err != nil {
return err
Expand Down
6 changes: 2 additions & 4 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func NewManager(
p2pClient *p2p.Client,
logger types.Logger,
) (*Manager, error) {

proposerAddress, err := getAddress(proposerKey)
if err != nil {
return nil, err
Expand Down Expand Up @@ -135,7 +134,7 @@ func (m *Manager) Start(ctx context.Context, isAggregator bool) error {
m.logger.Info("Starting the block manager")

if isAggregator {
//make sure local signing key is the registered on the hub
// make sure local signing key is the registered on the hub
slProposerKey := m.settlementClient.GetProposer().PublicKey.Bytes()
localProposerKey, _ := m.proposerKey.GetPublic().Raw()
if !bytes.Equal(slProposerKey, localProposerKey) {
Expand Down Expand Up @@ -176,7 +175,7 @@ func (m *Manager) syncBlockManager(ctx context.Context) error {
resultRetrieveBatch, err := m.getLatestBatchFromSL(ctx)
// Set the syncTarget according to the result
if err != nil {
//TODO: separate between fresh rollapp and non-registred rollapp
// TODO: separate between fresh rollapp and non-registred rollapp
if 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.
Expand Down Expand Up @@ -218,7 +217,6 @@ func (m *Manager) EventListener(ctx context.Context, isAggregator bool) {
if !isAggregator {
go utils.SubscribeAndHandleEvents(ctx, m.pubsub, "ApplyBlockLoop", p2p.EventQueryNewNewGossipedBlock, m.applyBlockCallback, m.logger, 100)
}

}

func (m *Manager) healthStatusEventCallback(event pubsub.Message) {
Expand Down
22 changes: 12 additions & 10 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func TestInitialState(t *testing.T) {
privKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
p2pClient, err := p2p.NewClient(config.P2PConfig{
GossipCacheSize: 50,
BoostrapTime: 30 * time.Second}, privKey, "TestChain", logger)
BoostrapTime: 30 * time.Second,
}, privKey, "TestChain", logger)
assert.NoError(err)
assert.NotNil(p2pClient)

Expand Down Expand Up @@ -94,7 +95,6 @@ func TestInitialState(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

dalc := getMockDALC(logger)
agg, err := NewManager(key, conf, c.genesis, c.store, nil, proxyApp, dalc, settlementlc,
nil, pubsubServer, p2pClient, logger)
Expand Down Expand Up @@ -134,11 +134,11 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
time.Sleep(time.Millisecond * 500)
}

//Initially sync target is 0
// Initially sync target is 0
assert.True(t, manager.syncTarget == 0)
assert.True(t, manager.store.Height() == 0)

//enough time to sync and produce blocks
// enough time to sync and produce blocks
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
defer cancel()
// Capture the error returned by manager.Start.
Expand All @@ -151,7 +151,7 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
}()
<-ctx.Done()
assert.True(t, manager.syncTarget == batch.EndHeight)
//validate that we produced blocks
// validate that we produced blocks
assert.Greater(t, manager.store.Height(), batch.EndHeight)
}

Expand Down Expand Up @@ -376,8 +376,10 @@ func TestProduceBlockFailAfterCommit(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
app.On("Commit", mock.Anything).Return(abci.ResponseCommit{Data: tc.AppCommitHash[:]}).Once()
app.On("Info", mock.Anything).Return(abci.ResponseInfo{LastBlockHeight: tc.LastAppBlockHeight,
LastBlockAppHash: tc.LastAppCommitHash[:]}).Once()
app.On("Info", mock.Anything).Return(abci.ResponseInfo{
LastBlockHeight: tc.LastAppBlockHeight,
LastBlockAppHash: tc.LastAppCommitHash[:],
}).Once()
mockStore.ShouldFailSetHeight = tc.shouldFailSetSetHeight
mockStore.ShoudFailUpdateState = tc.shouldFailUpdateState
_ = manager.produceBlock(context.Background(), true)
Expand Down Expand Up @@ -405,7 +407,7 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) {
// Init manager
managerConfig := getManagerConfig()
managerConfig.BlockBatchSize = 1000
managerConfig.BlockBatchMaxSizeBytes = batchLimitBytes //enough for 2 block, not enough for 10 blocks
managerConfig.BlockBatchMaxSizeBytes = batchLimitBytes // enough for 2 block, not enough for 10 blocks
manager, err := getManager(managerConfig, nil, nil, 1, 1, 0, proxyApp, nil)
require.NoError(err)

Expand Down Expand Up @@ -452,8 +454,8 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) {
assert.Equal(batch.EndHeight, batch.StartHeight+uint64(len(batch.Blocks))-1)
assert.Less(batch.EndHeight, endHeight)

//validate next added block to batch would have been actually too big
//First relax the byte limit so we could proudce larger batch
// validate next added block to batch would have been actually too big
// First relax the byte limit so we could proudce larger batch
manager.conf.BlockBatchMaxSizeBytes = 10 * manager.conf.BlockBatchMaxSizeBytes
newBatch, err := manager.createNextDABatch(startHeight, batch.EndHeight+1)
assert.Greater(newBatch.ToProto().Size(), batchLimitBytes)
Expand Down
13 changes: 6 additions & 7 deletions block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ func (m *Manager) ProduceBlockLoop(ctx context.Context) {
defer tickerEmptyBlocksMaxTime.Stop()
}

//Allow the initial block to be empty
// Allow the initial block to be empty
produceEmptyBlock := true
for {
select {
//Context canceled
// Context canceled
case <-ctx.Done():
return
// If we got a request for an empty block produce it and don't wait for the ticker
case <-m.produceEmptyBlockCh:
produceEmptyBlock = true
//Empty blocks timeout
// Empty blocks timeout
case <-tickerEmptyBlocksMaxTimeCh:
m.logger.Debug(fmt.Sprintf("No transactions for %.2f seconds, producing empty block", m.conf.EmptyBlocksMaxTime.Seconds()))
produceEmptyBlock = true
//Produce block
// Produce block
case <-ticker.C:
err := m.produceBlock(ctx, produceEmptyBlock)
if err == types.ErrSkippedEmptyBlock {
Expand All @@ -55,13 +55,13 @@ func (m *Manager) ProduceBlockLoop(ctx context.Context) {
m.shouldProduceBlocksCh <- false
continue
}
//If empty blocks enabled, after block produced, reset the timeout timer
// If empty blocks enabled, after block produced, reset the timeout timer
if tickerEmptyBlocksMaxTime != nil {
produceEmptyBlock = false
tickerEmptyBlocksMaxTime.Reset(m.conf.EmptyBlocksMaxTime)
}

//Node's health check channel
// Node's health check channel
case shouldProduceBlocks := <-m.shouldProduceBlocksCh:
for !shouldProduceBlocks {
m.logger.Info("Stopped block production")
Expand Down Expand Up @@ -193,5 +193,4 @@ func (m *Manager) createTMSignature(block *types.Block, proposerAddress []byte,
return nil, fmt.Errorf("wrong signature")
}
return vote.Signature, nil

}
4 changes: 2 additions & 2 deletions block/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCreateEmptyBlocksEnableDisable(t *testing.T) {
manager, err := getManager(managerConfig, nil, nil, 1, 1, 0, proxyApp, nil)
require.NoError(err)

//Check initial height
// Check initial height
initialHeight := uint64(0)
require.Equal(initialHeight, manager.store.Height())

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestCreateEmptyBlocksNew(t *testing.T) {

mpool := mempoolv1.NewTxMempool(log.TestingLogger(), tmcfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(abciClient), 0)

//Check initial height
// Check initial height
expectedHeight := uint64(0)
assert.Equal(expectedHeight, manager.store.Height())

Expand Down
2 changes: 1 addition & 1 deletion block/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (m *Manager) pruneBlocks(retainHeight int64) (uint64, error) {
return 0, fmt.Errorf("failed to prune block store: %w", err)
}

//TODO: prune state/indexer and state/txindexer??
// TODO: prune state/indexer and state/txindexer??

return pruned, nil
}
6 changes: 3 additions & 3 deletions block/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func (m *Manager) fetchBatch(daMetaData *da.DASubmitMetaData) da.ResultRetrieveB
},
}
}
//batchRes.MetaData includes proofs necessary to open disputes with the Hub
// batchRes.MetaData includes proofs necessary to open disputes with the Hub
batchRes := m.retriever.RetrieveBatches(daMetaData)
//TODO(srene) : for invalid transactions there is no specific error code since it will need to be validated somewhere else for fraud proving.
//NMT proofs (availRes.MetaData.Proofs) are included in the result batchRes, necessary to be included in the dispute
// TODO(srene) : for invalid transactions there is no specific error code since it will need to be validated somewhere else for fraud proving.
// NMT proofs (availRes.MetaData.Proofs) are included in the result batchRes, necessary to be included in the dispute
return batchRes
}
8 changes: 4 additions & 4 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ func (m *Manager) SubmitLoop(ctx context.Context) {
ticker := time.NewTicker(m.conf.BatchSubmitMaxTime)
defer ticker.Stop()

//TODO: add submission trigger by batch size (should be signaled from the the block production)
// TODO: add submission trigger by batch size (should be signaled from the the block production)
for {
select {
//Context canceled
// Context canceled
case <-ctx.Done():
return
// trigger by time
Expand All @@ -31,7 +31,7 @@ func (m *Manager) handleSubmissionTrigger(ctx context.Context) {
// SyncTarget is the height of the last block in the last batch as seen by this node.
syncTarget := atomic.LoadUint64(&m.syncTarget)
height := m.store.Height()
//no new blocks produced yet
// no new blocks produced yet
if height <= syncTarget {
return
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func (m *Manager) createNextDABatch(startHeight uint64, endHeight uint64) (*type
batch.Blocks = append(batch.Blocks, block)
batch.Commits = append(batch.Commits, commit)

//Check if the batch size is too big
// Check if the batch size is too big
totalSize := batch.ToProto().Size()
if totalSize > int(m.conf.BlockBatchMaxSizeBytes) {
// Nil out the last block and commit
Expand Down
14 changes: 5 additions & 9 deletions block/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package block

import (
"context"
"crypto/ed25519"
"crypto/rand"
"fmt"
"sync"
Expand All @@ -13,8 +14,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/proxy"

"crypto/ed25519"

cosmosed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/libp2p/go-libp2p/core/crypto"

Expand All @@ -24,9 +23,7 @@ import (
"github.com/dymensionxyz/dymint/types"
)

var (
ctx = context.Background()
)
var ctx = context.Background()

func TestBatchSubmissionHappyFlow(t *testing.T) {
require := require.New(t)
Expand All @@ -40,7 +37,7 @@ func TestBatchSubmissionHappyFlow(t *testing.T) {
manager, err := getManager(getManagerConfig(), nil, nil, 1, 1, 0, proxyApp, nil)
require.NoError(err)

//Check initial assertions
// Check initial assertions
initialHeight := uint64(0)
require.Zero(manager.store.Height())
require.True(manager.batchInProcess.Load() == false)
Expand Down Expand Up @@ -87,7 +84,7 @@ func TestBatchSubmissionFailedSubmission(t *testing.T) {
manager, err := getManagerWithProposerKey(getManagerConfig(), lib2pPrivKey, mockLayerI, nil, 1, 1, 0, proxyApp, nil)
require.NoError(err)

//Check initial assertions
// Check initial assertions
initialHeight := uint64(0)
require.Zero(manager.store.Height())
require.True(manager.batchInProcess.Load() == false)
Expand All @@ -108,7 +105,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)

}

func TestBatchSubmissionAfterTimeout(t *testing.T) {
Expand Down Expand Up @@ -141,7 +137,7 @@ func TestBatchSubmissionAfterTimeout(t *testing.T) {
manager, err := getManager(managerConfig, nil, nil, 1, 1, 0, proxyApp, nil)
require.NoError(err)

//Check initial height
// Check initial height
initialHeight := uint64(0)
require.Equal(initialHeight, manager.store.Height())
require.True(manager.batchInProcess.Load() == false)
Expand Down
3 changes: 2 additions & 1 deletion block/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func getManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt
p2pKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
p2pClient, err := p2p.NewClient(config.P2PConfig{
GossipCacheSize: 50,
BoostrapTime: 30 * time.Second}, p2pKey, "TestChain", logger)
BoostrapTime: 30 * time.Second,
}, p2pKey, "TestChain", logger)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions block/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package block

//TODO: move to types package

// TODO: move to types package
type blockSource string

const (
Expand Down
4 changes: 1 addition & 3 deletions cmd/dymint/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"github.com/tendermint/tendermint/proxy"
)

var (
genesisHash []byte
)
var genesisHash []byte

// NewRunNodeCmd returns the command that allows the CLI to start a node.
// It can be used with a custom PrivValidator and in-process ABCI application.
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type NodeConfig struct {
SettlementLayer string `mapstructure:"settlement_layer"`
SettlementConfig settlement.Config `mapstructure:",squash"`
Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"`
//Config params for mock grpc da
// Config params for mock grpc da
DAGrpc grpc.Config `mapstructure:",squash"`
BootstrapTime time.Duration `mapstructure:"bootstrap_time"`
}
Expand All @@ -59,7 +59,7 @@ type BlockManagerConfig struct {
func (nc *NodeConfig) GetViperConfig(cmd *cobra.Command, homeDir string) error {
v := viper.GetViper()

//Loads dymint toml config file
// Loads dymint toml config file
EnsureRoot(homeDir, nil)
v.SetConfigName("dymint")
v.AddConfigPath(homeDir) // search root directory
Expand Down Expand Up @@ -138,7 +138,7 @@ func (c NodeConfig) Validate() error {
}
}

//TODO: validate DA config
// TODO: validate DA config

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ func TestViperAndCobra(t *testing.T) {
assert.Equal(uint64(10), nc.BlockBatchSize)
}

//TODO: check invalid config
// TODO: check invalid config
Loading
Loading