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
2 changes: 1 addition & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewManager(
conf.DABlockTime = defaultDABlockTime
}

exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, eventBus, logger)
exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, conf.FraudProofs, eventBus, logger)
if s.LastBlockHeight+1 == genesis.InitialHeight {
res, err := exec.InitChain(genesis)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
flagDABlockTime = "rollmint.da_block_time"
flagDAStartHeight = "rollmint.da_start_height"
flagNamespaceID = "rollmint.namespace_id"
flagFraudProofs = "rollmint.experimental_insecure_fraud_proofs"
)

// NodeConfig stores rollmint node configuration.
Expand All @@ -43,6 +44,7 @@ type BlockManagerConfig struct {
// DAStartHeight allows skipping first DAStartHeight-1 blocks when querying for blocks.
DAStartHeight uint64 `mapstructure:"da_start_height"`
NamespaceID types.NamespaceID `mapstructure:"namespace_id"`
FraudProofs bool `mapstructure:"fraud_proofs"`
Comment thread
nashqueue marked this conversation as resolved.
}

// GetViperConfig reads configuration parameters from Viper instance.
Expand All @@ -56,6 +58,7 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
nc.DABlockTime = v.GetDuration(flagDABlockTime)
nc.BlockTime = v.GetDuration(flagBlockTime)
nsID := v.GetString(flagNamespaceID)
nc.FraudProofs = v.GetBool(flagFraudProofs)
bytes, err := hex.DecodeString(nsID)
if err != nil {
return err
Expand All @@ -76,4 +79,5 @@ func AddFlags(cmd *cobra.Command) {
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(flagFraudProofs, def.FraudProofs, "enable fraud proofs (experimental & insecure)")
}
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestViperAndCobra(t *testing.T) {
assert.NoError(cmd.Flags().Set(flagDAConfig, `{"json":true}`))
assert.NoError(cmd.Flags().Set(flagBlockTime, "1234s"))
assert.NoError(cmd.Flags().Set(flagNamespaceID, "0102030405060708"))
assert.NoError(cmd.Flags().Set(flagFraudProofs, "false"))

nc := DefaultNodeConfig
assert.NoError(nc.GetViperConfig(v))
Expand All @@ -35,4 +36,5 @@ func TestViperAndCobra(t *testing.T) {
assert.Equal(`{"json":true}`, nc.DAConfig)
assert.Equal(1234*time.Second, nc.BlockTime)
assert.Equal(types.NamespaceID{1, 2, 3, 4, 5, 6, 7, 8}, nc.NamespaceID)
assert.Equal(false, nc.FraudProofs)
}
1 change: 1 addition & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var DefaultNodeConfig = NodeConfig{
BlockManagerConfig: BlockManagerConfig{
BlockTime: 30 * time.Second,
NamespaceID: types.NamespaceID{},
FraudProofs: false,
Comment thread
tzdybal marked this conversation as resolved.
},
DALayer: "mock",
DAConfig: "",
Expand Down
1 change: 1 addition & 0 deletions node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func createNode(ctx context.Context, n int, isMalicious bool, aggregator bool, d
bmConfig := config.BlockManagerConfig{
BlockTime: 300 * time.Millisecond,
NamespaceID: rmtypes.NamespaceID{8, 7, 6, 5, 4, 3, 2, 1},
FraudProofs: true,
}
for i := 0; i < len(keys); i++ {
if i == n {
Expand Down
36 changes: 18 additions & 18 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"github.com/celestiaorg/rollmint/types"
)

var fraudProofsEnabled = true

// BlockExecutor creates and applies blocks and maintains state.
type BlockExecutor struct {
proposerAddress []byte
namespaceID types.NamespaceID
chainID string
proxyApp proxy.AppConnConsensus
mempool mempool.Mempool
proposerAddress []byte
namespaceID types.NamespaceID
chainID string
proxyApp proxy.AppConnConsensus
mempool mempool.Mempool
fraudProofsEnabled bool

eventBus *tmtypes.EventBus

Expand All @@ -38,15 +37,16 @@ type BlockExecutor struct {

// NewBlockExecutor creates new instance of BlockExecutor.
// Proposer address and namespace ID will be used in all newly created blocks.
func NewBlockExecutor(proposerAddress []byte, namespaceID [8]byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, eventBus *tmtypes.EventBus, logger log.Logger) *BlockExecutor {
func NewBlockExecutor(proposerAddress []byte, namespaceID [8]byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, fraudProofsEnabled bool, eventBus *tmtypes.EventBus, logger log.Logger) *BlockExecutor {
return &BlockExecutor{
proposerAddress: proposerAddress,
namespaceID: namespaceID,
chainID: chainID,
proxyApp: proxyApp,
mempool: mempool,
eventBus: eventBus,
logger: logger,
proposerAddress: proposerAddress,
namespaceID: namespaceID,
chainID: chainID,
proxyApp: proxyApp,
mempool: mempool,
fraudProofsEnabled: fraudProofsEnabled,
eventBus: eventBus,
logger: logger,
}
}

Expand Down Expand Up @@ -293,7 +293,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t
currentIsrs := block.Data.IntermediateStateRoots.RawRootsList
currentIsrIndex := 0

if fraudProofsEnabled && currentIsrs != nil {
if e.fraudProofsEnabled && currentIsrs != nil {
expectedLength := len(block.Data.Txs) + 2
// BeginBlock + DeliverTxs + EndBlock
if len(currentIsrs) != expectedLength {
Expand All @@ -318,7 +318,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t
})

genAndGossipFraudProofIfNeeded := func(beginBlockRequest *abci.RequestBeginBlock, deliverTxRequests []*abci.RequestDeliverTx, endBlockRequest *abci.RequestEndBlock) (err error) {
if !fraudProofsEnabled {
if !e.fraudProofsEnabled {
return nil
}
isr, err := e.getAppHash()
Expand Down Expand Up @@ -391,7 +391,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t
return nil, err
}

if fraudProofsEnabled && block.Data.IntermediateStateRoots.RawRootsList == nil {
if e.fraudProofsEnabled && block.Data.IntermediateStateRoots.RawRootsList == nil {
// Block producer: Initial ISRs generated here
block.Data.IntermediateStateRoots.RawRootsList = ISRs
}
Expand Down
24 changes: 20 additions & 4 deletions state/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/celestiaorg/rollmint/types"
)

func TestCreateBlock(t *testing.T) {
func doTestCreateBlock(t *testing.T, fraudProofsEnabled bool) {
assert := assert.New(t)
require := require.New(t)

Expand All @@ -39,7 +39,7 @@ func TestCreateBlock(t *testing.T) {
nsID := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}

mpool := mempoolv1.NewTxMempool(logger, cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client), 0)
executor := NewBlockExecutor([]byte("test address"), nsID, "test", mpool, proxy.NewAppConnConsensus(client), nil, logger)
executor := NewBlockExecutor([]byte("test address"), nsID, "test", mpool, proxy.NewAppConnConsensus(client), fraudProofsEnabled, nil, logger)

state := types.State{}
state.ConsensusParams.Block.MaxBytes = 100
Expand Down Expand Up @@ -70,7 +70,15 @@ func TestCreateBlock(t *testing.T) {
assert.Len(block.Data.Txs, 2)
}

func TestApplyBlock(t *testing.T) {
func TestCreateBlockWithFraudProofsDisabled(t *testing.T) {
doTestCreateBlock(t, false)
}

func TestCreateBlockWithFraudProofsEnabled(t *testing.T) {
doTestCreateBlock(t, true)
}

func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
assert := assert.New(t)
require := require.New(t)

Expand Down Expand Up @@ -102,7 +110,7 @@ func TestApplyBlock(t *testing.T) {
mpool := mempoolv1.NewTxMempool(logger, cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client), 0)
eventBus := tmtypes.NewEventBus()
require.NoError(eventBus.Start())
executor := NewBlockExecutor([]byte("test address"), nsID, chainID, mpool, proxy.NewAppConnConsensus(client), eventBus, logger)
executor := NewBlockExecutor([]byte("test address"), nsID, chainID, mpool, proxy.NewAppConnConsensus(client), fraudProofsEnabled, eventBus, logger)

txQuery, err := query.New("tm.event='Tx'")
require.NoError(err)
Expand Down Expand Up @@ -190,3 +198,11 @@ func TestApplyBlock(t *testing.T) {
}
}
}

func TestApplyBlockWithFraudProofsDisabled(t *testing.T) {
doTestApplyBlock(t, false)
}

func TestApplyBlockWithFraudProofsEnabled(t *testing.T) {
doTestApplyBlock(t, true)
}