github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/consensus/replay_stubs.go (about) 1 package consensus 2 3 import ( 4 abci "github.com/badrootd/nibiru-cometbft/abci/types" 5 "github.com/badrootd/nibiru-cometbft/libs/clist" 6 mempl "github.com/badrootd/nibiru-cometbft/mempool" 7 cmtstate "github.com/badrootd/nibiru-cometbft/proto/tendermint/state" 8 "github.com/badrootd/nibiru-cometbft/proxy" 9 "github.com/badrootd/nibiru-cometbft/types" 10 ) 11 12 //----------------------------------------------------------------------------- 13 14 type emptyMempool struct{} 15 16 var _ mempl.Mempool = emptyMempool{} 17 18 func (emptyMempool) Lock() {} 19 func (emptyMempool) Unlock() {} 20 func (emptyMempool) Size() int { return 0 } 21 func (emptyMempool) SizeBytes() int64 { return 0 } 22 func (emptyMempool) CheckTx(_ types.Tx, _ func(*abci.Response), _ mempl.TxInfo) error { 23 return nil 24 } 25 26 func (txmp emptyMempool) RemoveTxByKey(txKey types.TxKey) error { 27 return nil 28 } 29 30 func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} } 31 func (emptyMempool) ReapMaxTxs(n int) types.Txs { return types.Txs{} } 32 func (emptyMempool) Update( 33 _ int64, 34 _ types.Txs, 35 _ []*abci.ResponseDeliverTx, 36 _ mempl.PreCheckFunc, 37 _ mempl.PostCheckFunc, 38 ) error { 39 return nil 40 } 41 func (emptyMempool) Flush() {} 42 func (emptyMempool) FlushAppConn() error { return nil } 43 func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) } 44 func (emptyMempool) EnableTxsAvailable() {} 45 func (emptyMempool) TxsBytes() int64 { return 0 } 46 47 func (emptyMempool) TxsFront() *clist.CElement { return nil } 48 func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil } 49 50 func (emptyMempool) InitWAL() error { return nil } 51 func (emptyMempool) CloseWAL() {} 52 53 //----------------------------------------------------------------------------- 54 // mockProxyApp uses ABCIResponses to give the right results. 55 // 56 // Useful because we don't want to call Commit() twice for the same block on 57 // the real app. 58 59 func newMockProxyApp(appHash []byte, abciResponses *cmtstate.ABCIResponses) proxy.AppConnConsensus { 60 clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{ 61 appHash: appHash, 62 abciResponses: abciResponses, 63 }) 64 cli, _ := clientCreator.NewABCIClient() 65 err := cli.Start() 66 if err != nil { 67 panic(err) 68 } 69 return proxy.NewAppConnConsensus(cli, proxy.NopMetrics()) 70 } 71 72 type mockProxyApp struct { 73 abci.BaseApplication 74 75 appHash []byte 76 txCount int 77 abciResponses *cmtstate.ABCIResponses 78 } 79 80 func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { 81 r := mock.abciResponses.DeliverTxs[mock.txCount] 82 mock.txCount++ 83 if r == nil { 84 return abci.ResponseDeliverTx{} 85 } 86 return *r 87 } 88 89 func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock { 90 mock.txCount = 0 91 return *mock.abciResponses.EndBlock 92 } 93 94 func (mock *mockProxyApp) Commit() abci.ResponseCommit { 95 return abci.ResponseCommit{Data: mock.appHash} 96 }