Skip to content
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
3 changes: 1 addition & 2 deletions block/block-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ config|config.BlockManagerConfig|block manager configurations (see config option
genesis|*cmtypes.GenesisDoc|initialize the block manager with genesis state (genesis configuration defined in `config/genesis.json` file under the app directory)
store|store.Store|local datastore for storing rollup blocks and states (default local store path is `$db_dir/rollkit` and `db_dir` specified in the `config.toml` file under the app directory)
mempool, proxyapp, eventbus|mempool.Mempool, proxy.AppConnConsensus, *cmtypes.EventBus|for initializing the executor (state transition function). mempool is also used in the manager to check for availability of transactions for lazy block production
dalc|da.DataAvailabilityLayerClient|the data availability light client used to submit and retrieve blocks to DA network
dalc|da.DAClient|the data availability light client used to submit and retrieve blocks to DA network
blockstore|*goheaderstore.Store[*types.Block]|to retrieve blocks gossiped over the P2P network

Block manager configuration options:
Expand All @@ -63,7 +63,6 @@ Block manager configuration options:
|BlockTime|time.Duration|time interval used for block production and block retrieval from block store ([`defaultBlockTime`][defaultBlockTime])|
|DABlockTime|time.Duration|time interval used for both block publication to DA network and block retrieval from DA network ([`defaultDABlockTime`][defaultDABlockTime])|
|DAStartHeight|uint64|block retrieval from DA network starts from this height|
|NamespaceID|bytes|8 `byte` unique identifier of the rollup|

### Block Production

Expand Down
13 changes: 5 additions & 8 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ type Manager struct {

executor *state.BlockExecutor

dalc da.DataAvailabilityLayerClient
retriever da.BlockRetriever
dalc *da.DAClient
// daHeight is the height of the latest processed DA block
daHeight uint64

Expand Down Expand Up @@ -112,7 +111,7 @@ func NewManager(
store store.Store,
mempool mempool.Mempool,
proxyApp proxy.AppConnConsensus,
dalc da.DataAvailabilityLayerClient,
dalc *da.DAClient,
eventBus *cmtypes.EventBus,
logger log.Logger,
blockStore *goheaderstore.Store[*types.Block],
Expand Down Expand Up @@ -140,7 +139,7 @@ func NewManager(
conf.BlockTime = defaultBlockTime
}

exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, eventBus, logger)
exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, proxyApp, eventBus, logger)
if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) {
res, err := exec.InitChain(genesis)
if err != nil {
Expand Down Expand Up @@ -168,7 +167,6 @@ func NewManager(
store: store,
executor: exec,
dalc: dalc,
retriever: dalc.(da.BlockRetriever), // TODO(tzdybal): do it in more gentle way (after MVP)
daHeight: s.DAHeight,
// channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary
HeaderCh: make(chan *types.SignedHeader, channelLength),
Expand Down Expand Up @@ -197,9 +195,8 @@ func getAddress(key crypto.PrivKey) ([]byte, error) {
}

// SetDALC is used to set DataAvailabilityLayerClient used by Manager.
func (m *Manager) SetDALC(dalc da.DataAvailabilityLayerClient) {
func (m *Manager) SetDALC(dalc *da.DAClient) {
m.dalc = dalc
m.retriever = dalc.(da.BlockRetriever)
}

// GetStoreHeight returns the manager's store height
Expand Down Expand Up @@ -525,7 +522,7 @@ func (m *Manager) processNextDABlock(ctx context.Context) error {

func (m *Manager) fetchBlock(ctx context.Context, daHeight uint64) (da.ResultRetrieveBlocks, error) {
var err error
blockRes := m.retriever.RetrieveBlocks(ctx, daHeight)
blockRes := m.dalc.RetrieveBlocks(ctx, daHeight)
switch blockRes.Code {
case da.StatusError:
err = fmt.Errorf("failed to retrieve block: %s", blockRes.Message)
Expand Down
18 changes: 3 additions & 15 deletions block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"testing"
"time"

"github.com/cometbft/cometbft/libs/log"
cmtypes "github.com/cometbft/cometbft/types"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

goDATest "github.com/rollkit/go-da/test"
"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/da"
mockda "github.com/rollkit/rollkit/da/mock"
"github.com/rollkit/rollkit/store"
test "github.com/rollkit/rollkit/test/log"
"github.com/rollkit/rollkit/types"
Expand Down Expand Up @@ -71,18 +70,14 @@ func TestInitialState(t *testing.T) {

key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
conf := config.BlockManagerConfig{
BlockTime: 10 * time.Second,
NamespaceID: types.NamespaceID{1, 2, 3, 4, 5, 6, 7, 8},
BlockTime: 10 * time.Second,
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
assert := assert.New(t)
logger := test.NewFileLoggerCustom(t, test.TempLogFileName(t, c.name))
dalc := getMockDALC(logger)
defer func() {
require.NoError(t, dalc.Stop())
}()
dalc := &da.DAClient{DA: goDATest.NewDummyDA(), Logger: logger}
agg, err := NewManager(key, conf, c.genesis, c.store, nil, nil, dalc, nil, logger, nil)
assert.NoError(err)
Comment thread
gupadhyaya marked this conversation as resolved.
Resolved
assert.NotNil(agg)
Comment thread
gupadhyaya marked this conversation as resolved.
Resolved
Expand All @@ -95,13 +90,6 @@ func TestInitialState(t *testing.T) {
}
}

func getMockDALC(logger log.Logger) da.DataAvailabilityLayerClient {
dalc := &mockda.DataAvailabilityLayerClient{}
_ = dalc.Init([8]byte{}, nil, nil, logger)
_ = dalc.Start()
return dalc
}

func TestIsDAIncluded(t *testing.T) {
require := require.New(t)

Expand Down
26 changes: 5 additions & 21 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package config

import (
"encoding/hex"
"time"

cmcfg "github.com/cometbft/cometbft/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/rollkit/rollkit/types"
)

const (
flagAggregator = "rollkit.aggregator"
flagDALayer = "rollkit.da_layer"
flagDAConfig = "rollkit.da_config"
flagDAAddress = "rollkit.da_address"
flagBlockTime = "rollkit.block_time"
flagDABlockTime = "rollkit.da_block_time"
flagDAStartHeight = "rollkit.da_start_height"
flagNamespaceID = "rollkit.namespace_id"
flagLight = "rollkit.light"
flagTrustedHash = "rollkit.trusted_hash"
flagLazyAggregator = "rollkit.lazy_aggregator"
Expand All @@ -35,8 +30,7 @@ type NodeConfig struct {
// parameters below are Rollkit specific and read from config
Aggregator bool `mapstructure:"aggregator"`
BlockManagerConfig `mapstructure:",squash"`
DALayer string `mapstructure:"da_layer"`
DAConfig string `mapstructure:"da_config"`
DAAddress string `mapstructure:"da_address"`
Light bool `mapstructure:"light"`
HeaderConfig `mapstructure:",squash"`
LazyAggregator bool `mapstructure:"lazy_aggregator"`
Expand All @@ -54,8 +48,7 @@ type BlockManagerConfig struct {
// DABlockTime informs about block time of underlying data availability layer
DABlockTime time.Duration `mapstructure:"da_block_time"`
// DAStartHeight allows skipping first DAStartHeight-1 blocks when querying for blocks.
DAStartHeight uint64 `mapstructure:"da_start_height"`
NamespaceID types.NamespaceID `mapstructure:"namespace_id"`
DAStartHeight uint64 `mapstructure:"da_start_height"`
}

// GetNodeConfig translates Tendermint's configuration into Rollkit configuration.
Expand Down Expand Up @@ -87,19 +80,12 @@ func GetNodeConfig(nodeConf *NodeConfig, cmConf *cmcfg.Config) {
// This method is called in cosmos-sdk.
func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
nc.Aggregator = v.GetBool(flagAggregator)
nc.DALayer = v.GetString(flagDALayer)
nc.DAConfig = v.GetString(flagDAConfig)
nc.DAAddress = v.GetString(flagDAAddress)
nc.DAStartHeight = v.GetUint64(flagDAStartHeight)
nc.DABlockTime = v.GetDuration(flagDABlockTime)
nc.BlockTime = v.GetDuration(flagBlockTime)
nc.LazyAggregator = v.GetBool(flagLazyAggregator)
nsID := v.GetString(flagNamespaceID)
nc.Light = v.GetBool(flagLight)
bytes, err := hex.DecodeString(nsID)
if err != nil {
return err
}
copy(nc.NamespaceID[:], bytes)
nc.TrustedHash = v.GetString(flagTrustedHash)
return nil
}
Expand All @@ -111,12 +97,10 @@ func AddFlags(cmd *cobra.Command) {
def := DefaultNodeConfig
cmd.Flags().Bool(flagAggregator, def.Aggregator, "run node in aggregator mode")
cmd.Flags().Bool(flagLazyAggregator, def.LazyAggregator, "wait for transactions, don't build empty blocks")
cmd.Flags().String(flagDALayer, def.DALayer, "Data Availability Layer Client name (mock or grpc")
cmd.Flags().String(flagDAConfig, def.DAConfig, "Data Availability Layer Client config")
cmd.Flags().String(flagDAAddress, def.DAAddress, "DA address (host:port)")
cmd.Flags().Duration(flagBlockTime, def.BlockTime, "block time (for aggregator mode)")
cmd.Flags().Duration(flagDABlockTime, def.DABlockTime, "DA chain block time (for syncing)")
cmd.Flags().Uint64(flagDAStartHeight, def.DAStartHeight, "starting DA block height (for syncing)")
cmd.Flags().BytesHex(flagNamespaceID, def.NamespaceID[:], "namespace identifies (8 bytes in hex)")
cmd.Flags().Bool(flagLight, def.Light, "run light client")
cmd.Flags().String(flagTrustedHash, def.TrustedHash, "initial trusted hash to start the header exchange service")
}
10 changes: 2 additions & 8 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"

"github.com/rollkit/rollkit/types"
)

func TestGetNodeConfig(t *testing.T) {
Expand Down Expand Up @@ -47,17 +45,13 @@ func TestViperAndCobra(t *testing.T) {
assert.NoError(v.BindPFlags(cmd.Flags()))

assert.NoError(cmd.Flags().Set(flagAggregator, "true"))
assert.NoError(cmd.Flags().Set(flagDALayer, "foobar"))
assert.NoError(cmd.Flags().Set(flagDAConfig, `{"json":true}`))
assert.NoError(cmd.Flags().Set(flagDAAddress, `{"json":true}`))
assert.NoError(cmd.Flags().Set(flagBlockTime, "1234s"))
assert.NoError(cmd.Flags().Set(flagNamespaceID, "0102030405060708"))

nc := DefaultNodeConfig
assert.NoError(nc.GetViperConfig(v))

assert.Equal(true, nc.Aggregator)
assert.Equal("foobar", nc.DALayer)
assert.Equal(`{"json":true}`, nc.DAConfig)
assert.Equal(`{"json":true}`, nc.DAAddress)
assert.Equal(1234*time.Second, nc.BlockTime)
assert.Equal(types.NamespaceID{1, 2, 3, 4, 5, 6, 7, 8}, nc.NamespaceID)
}
8 changes: 2 additions & 6 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package config

import (
"time"

"github.com/rollkit/rollkit/types"
)

const (
Expand All @@ -25,11 +23,9 @@ var DefaultNodeConfig = NodeConfig{
BlockManagerConfig: BlockManagerConfig{
BlockTime: 1 * time.Second,
DABlockTime: 15 * time.Second,
NamespaceID: types.NamespaceID{},
},
DALayer: "newda",
DAConfig: "",
Light: false,
DAAddress: ":26650",
Light: false,
HeaderConfig: HeaderConfig{
TrustedHash: "",
},
Expand Down
Loading