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

feat: Add support for avail as a DA #355

Merged
merged 15 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
run:
concurrency: 4
timeout: 5m
modules-download-mode: readonly
# mempool and indexer code is borrowed from Tendermint
Expand All @@ -13,7 +14,6 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gofmt
- goimports
Expand All @@ -22,10 +22,8 @@ linters:
- ineffassign
- misspell
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- gosec
- gocyclo

Expand Down
11 changes: 6 additions & 5 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func NewManager(
}

// TODO((#119): Probably should be validated and manage default on config init.
if conf.BlockBatchSizeBytes == 0 {
logger.Info("WARNING: using default DA batch size bytes limit", "BlockBatchSizeBytes", config.DefaultNodeConfig.BlockBatchSizeBytes)
conf.BlockBatchSizeBytes = config.DefaultNodeConfig.BlockBatchSizeBytes
if conf.BlockBatchMaxSizeBytes == 0 {
logger.Info("WARNING: using default DA batch size bytes limit", "BlockBatchSizeBytes", config.DefaultNodeConfig.BlockBatchMaxSizeBytes)
conf.BlockBatchMaxSizeBytes = config.DefaultNodeConfig.BlockBatchMaxSizeBytes
}
if conf.BatchSubmitMaxTime == 0 {
logger.Info("WARNING: using default DA batch submit max time", "BatchSubmitMaxTime", config.DefaultNodeConfig.BatchSubmitMaxTime)
Expand Down Expand Up @@ -315,6 +315,7 @@ func (m *Manager) ProduceBlockLoop(ctx context.Context) {

var tickerEmptyBlocksMaxTime *time.Ticker
var tickerEmptyBlocksMaxTimeCh <-chan time.Time
// Setup ticker for empty blocks if enabled
if m.conf.EmptyBlocksMaxTime > 0 {
tickerEmptyBlocksMaxTime = time.NewTicker(m.conf.EmptyBlocksMaxTime)
tickerEmptyBlocksMaxTimeCh = tickerEmptyBlocksMaxTime.C
Expand All @@ -330,7 +331,7 @@ func (m *Manager) ProduceBlockLoop(ctx context.Context) {
return
//Empty blocks timeout
case <-tickerEmptyBlocksMaxTimeCh:
m.logger.Error("No transactions for too long, allowing to produce empty block")
m.logger.Error(fmt.Sprintf("No transactions for %.2f seconds, producing empty block", m.conf.EmptyBlocksMaxTime.Seconds()))
produceEmptyBlock = true
//Produce block
case <-ticker.C:
Expand Down Expand Up @@ -797,7 +798,7 @@ func (m *Manager) createNextDABatch(startHeight uint64, endHeight uint64) (*type

//Check if the batch size is too big
totalSize := batch.ToProto().Size()
if totalSize > int(m.conf.BlockBatchSizeBytes) {
if totalSize > int(m.conf.BlockBatchMaxSizeBytes) {
// Nil out the last block and commit
batch.Blocks[len(batch.Blocks)-1] = nil
batch.Commits[len(batch.Commits)-1] = nil
Expand Down
11 changes: 7 additions & 4 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
go manager.ProduceBlockLoop(ctx)
<-ctx.Done()
assert.Equal(t, lastStoreHeight, manager.store.Height())
// Wait until produce block loop is done
time.Sleep(time.Second * 1)

t.Log("Sync the manager")
ctx, cancel = context.WithTimeout(context.Background(), time.Second*2)
Expand All @@ -158,6 +160,8 @@ func TestProduceOnlyAfterSynced(t *testing.T) {
<-ctx.Done()
require.Greater(t, manager.store.Height(), lastStoreHeight)
assert.Equal(t, batch.EndHeight, manager.store.Height())
// Wait until manager is done
time.Sleep(time.Second * 4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why u need it? isn't the manager stopped by the context already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is but it takes the manager time due to the other case running (so the context.Done() case doesn't get a context switch immediately but only after a few seconds).
the tests kept failing so this fixed it.
prob it's bit dirty. if you have a better idea..


t.Log("Validate blocks are produced")
ctx, cancel = context.WithTimeout(context.Background(), time.Second*3)
Expand Down Expand Up @@ -409,7 +413,7 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) {
// Init manager
managerConfig := getManagerConfig()
managerConfig.BlockBatchSize = 1000
managerConfig.BlockBatchSizeBytes = 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 @@ -447,7 +451,7 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) {
assert.NoError(err)

assert.Equal(batch.StartHeight, startHeight)
assert.LessOrEqual(batch.ToProto().Size(), int(managerConfig.BlockBatchSizeBytes))
assert.LessOrEqual(batch.ToProto().Size(), int(managerConfig.BlockBatchMaxSizeBytes))

if !tc.expectedToBeTruncated {
assert.Equal(batch.EndHeight, endHeight)
Expand All @@ -457,7 +461,7 @@ func TestCreateNextDABatchWithBytesLimit(t *testing.T) {

//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.BlockBatchSizeBytes = 10 * manager.conf.BlockBatchSizeBytes
manager.conf.BlockBatchMaxSizeBytes = 10 * manager.conf.BlockBatchMaxSizeBytes
newBatch, err := manager.createNextDABatch(startHeight, batch.EndHeight+1)
assert.Greater(newBatch.ToProto().Size(), batchLimitBytes)

Expand Down Expand Up @@ -580,7 +584,6 @@ func getManagerConfig() config.BlockManagerConfig {
BlockTime: 100 * time.Millisecond,
BlockBatchSize: defaultBatchSize,
BatchSubmitMaxTime: 30 * time.Minute,
DAStartHeight: 0,
NamespaceID: "0102030405060708",
}
}
2 changes: 1 addition & 1 deletion cmd/dymint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/dymensionxyz/dymint/cmd/dymint/commands"
"github.com/dymensionxyz/dymint/config"
"github.com/tendermint/tendermint/cmd/tendermint/commands/debug"
"github.com/tendermint/tendermint/cmd/cometbft/commands/debug"
"github.com/tendermint/tendermint/libs/cli"
)

Expand Down
32 changes: 14 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
)

const (
flagAggregator = "dymint.aggregator"
flagDALayer = "dymint.da_layer"
flagDAConfig = "dymint.da_config"
flagBlockTime = "dymint.block_time"
flagEmptyBlocksMaxTime = "dymint.empty_blocks_max_time"
flagBatchSubmitMaxTime = "dymint.batch_submit_max_time"
flagDAStartHeight = "dymint.da_start_height"
flagNamespaceID = "dymint.namespace_id"
flagBlockBatchSize = "dymint.block_batch_size"
flagBlockBatchSizeBytes = "dymint.block_batch_size_bytes"
flagAggregator = "dymint.aggregator"
flagDALayer = "dymint.da_layer"
flagDAConfig = "dymint.da_config"
flagBlockTime = "dymint.block_time"
flagEmptyBlocksMaxTime = "dymint.empty_blocks_max_time"
flagBatchSubmitMaxTime = "dymint.batch_submit_max_time"
// TODO(omritoptix): Namespace ID should be part of the DA config
flagNamespaceID = "dymint.namespace_id"
flagBlockBatchSize = "dymint.block_batch_size"
flagBlockBatchMaxSizeBytes = "dymint.block_batch_max_size_bytes"
)

const (
Expand Down Expand Up @@ -61,13 +61,11 @@ type BlockManagerConfig struct {
EmptyBlocksMaxTime time.Duration `mapstructure:"empty_blocks_max_time"`
// BatchSubmitMaxTime defines how long should block manager wait for before submitting batch
BatchSubmitMaxTime time.Duration `mapstructure:"batch_submit_max_time"`
// DAStartHeight allows skipping first DAStartHeight-1 blocks when querying for blocks.
DAStartHeight uint64 `mapstructure:"da_start_height"`
NamespaceID string `mapstructure:"namespace_id"`
NamespaceID string `mapstructure:"namespace_id"`
// The size of the batch in blocks. Every batch we'll write to the DA and the settlement layer.
BlockBatchSize uint64 `mapstructure:"block_batch_size"`
// The size of the batch in Bytes. Every batch we'll write to the DA and the settlement layer.
BlockBatchSizeBytes uint64 `mapstructure:"block_batch_size_bytes"`
BlockBatchMaxSizeBytes uint64 `mapstructure:"block_batch_size_bytes"`
}

// GetViperConfig reads configuration parameters from Viper instance.
Expand All @@ -78,12 +76,11 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
nc.DALayer = v.GetString(flagDALayer)
nc.DAConfig = v.GetString(flagDAConfig)
nc.SettlementLayer = v.GetString(flagSettlementLayer)
nc.DAStartHeight = v.GetUint64(flagDAStartHeight)
nc.BlockTime = v.GetDuration(flagBlockTime)
nc.EmptyBlocksMaxTime = v.GetDuration(flagEmptyBlocksMaxTime)
nc.BatchSubmitMaxTime = v.GetDuration(flagBatchSubmitMaxTime)
nc.BlockBatchSize = v.GetUint64(flagBlockBatchSize)
nc.BlockBatchSizeBytes = v.GetUint64(flagBlockBatchSizeBytes)
nc.BlockBatchMaxSizeBytes = v.GetUint64(flagBlockBatchMaxSizeBytes)
nc.NamespaceID = v.GetString(flagNamespaceID)

nc.SettlementConfig.NodeAddress = v.GetString(flagSLNodeAddress)
Expand All @@ -109,10 +106,9 @@ func AddFlags(cmd *cobra.Command) {
cmd.Flags().Duration(flagBlockTime, def.BlockTime, "block time (for aggregator mode)")
cmd.Flags().Duration(flagEmptyBlocksMaxTime, def.EmptyBlocksMaxTime, "max time for empty blocks (for aggregator mode)")
cmd.Flags().Duration(flagBatchSubmitMaxTime, def.BatchSubmitMaxTime, "max time for batch submit (for aggregator mode)")
cmd.Flags().Uint64(flagDAStartHeight, def.DAStartHeight, "starting DA block height (for syncing)")
cmd.Flags().String(flagNamespaceID, def.NamespaceID, "namespace identifies (8 bytes in hex)")
cmd.Flags().Uint64(flagBlockBatchSize, def.BlockBatchSize, "block batch size")
cmd.Flags().Uint64(flagBlockBatchSizeBytes, def.BlockBatchSizeBytes, "block batch size in bytes")
cmd.Flags().Uint64(flagBlockBatchMaxSizeBytes, def.BlockBatchMaxSizeBytes, "block batch max size in bytes")

cmd.Flags().String(flagSettlementLayer, def.SettlementLayer, "Settlement Layer Client name")
cmd.Flags().String(flagSLNodeAddress, def.SettlementConfig.NodeAddress, "Settlement Layer RPC node address")
Expand Down
12 changes: 6 additions & 6 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var DefaultNodeConfig = NodeConfig{
Seeds: ""},
Aggregator: true,
BlockManagerConfig: BlockManagerConfig{
BlockTime: 200 * time.Millisecond,
EmptyBlocksMaxTime: 60 * time.Second,
BatchSubmitMaxTime: 600 * time.Second,
NamespaceID: "000000000000ffff",
BlockBatchSize: 500,
BlockBatchSizeBytes: 1500000},
BlockTime: 200 * time.Millisecond,
EmptyBlocksMaxTime: 60 * time.Second,
BatchSubmitMaxTime: 600 * time.Second,
NamespaceID: "000000000000ffff",
BlockBatchSize: 500,
BlockBatchMaxSizeBytes: 1500000},
DALayer: "mock",
SettlementLayer: "mock",
}
6 changes: 4 additions & 2 deletions contrib/githooks/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ repos:
# - https://github.com/golangci/golangci-lint
#
# - id: golangci-lint
- id: golangci-lint-mod
- id: golangci-lint-repo-mod
- repo: https://github.com/golangci/golangci-lint
rev: v1.53.3
hooks:
- id: golangci-lint
#
# # Invoking Custom Go Tools
# # - Configured *entirely* through the `args` attribute, ie:
Expand Down
Loading