feat!: Comet v0.38 Integration (#15519)
Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
marbar3778
cool-developer
Aaron Craelius
Matt Kocubinski
Julien Robert
parent
166be3766b
commit
6cee22df52
@@ -43,38 +43,13 @@ func (a *FilePlugin) writeToFile(file string, data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *FilePlugin) ListenBeginBlock(ctx context.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error {
|
||||
a.BlockHeight = req.Header.Height
|
||||
d1 := []byte(fmt.Sprintf("%d:::%v\n", a.BlockHeight, req))
|
||||
d2 := []byte(fmt.Sprintf("%d:::%v\n", a.BlockHeight, res))
|
||||
if err := a.writeToFile("begin-block-req", d1); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.writeToFile("begin-block-res", d2); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *FilePlugin) ListenEndBlock(ctx context.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error {
|
||||
func (a *FilePlugin) ListenFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error {
|
||||
d1 := []byte(fmt.Sprintf("%d:::%v\n", a.BlockHeight, req))
|
||||
d2 := []byte(fmt.Sprintf("%d:::%v\n", a.BlockHeight, req))
|
||||
if err := a.writeToFile("end-block-req", d1); err != nil {
|
||||
if err := a.writeToFile("finalize-block-req", d1); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.writeToFile("end-block-res", d2); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *FilePlugin) ListenDeliverTx(ctx context.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error {
|
||||
d1 := []byte(fmt.Sprintf("%d:::%v\n", a.BlockHeight, req))
|
||||
d2 := []byte(fmt.Sprintf("%d:::%v\n", a.BlockHeight, res))
|
||||
if err := a.writeToFile("deliver-tx-req", d1); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.writeToFile("deliver-tx-res", d2); err != nil {
|
||||
if err := a.writeToFile("finalize-block-res", d2); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
Binary file not shown.
@@ -17,22 +17,10 @@ type StdoutPlugin struct {
|
||||
BlockHeight int64
|
||||
}
|
||||
|
||||
func (a *StdoutPlugin) ListenBeginBlock(ctx context.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error {
|
||||
a.BlockHeight = req.Header.Height
|
||||
func (a *StdoutPlugin) ListenFinalizeBlock(ctx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error {
|
||||
a.BlockHeight = req.Height
|
||||
// process tx messages (i.e: sent to external system)
|
||||
fmt.Printf("listen-begin-block: block-height=%d req=%v res=%v", a.BlockHeight, req, res)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *StdoutPlugin) ListenEndBlock(ctx context.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error {
|
||||
// process end block messages (i.e: sent to external system)
|
||||
fmt.Printf("listen-end-block: block-height=%d req=%v res=%v", a.BlockHeight, req, res)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *StdoutPlugin) ListenDeliverTx(ctx context.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error {
|
||||
// process tx messages (i.e: sent to external system)
|
||||
fmt.Printf("listen-deliver-tx: block-height=%d req=%v res=%v", a.BlockHeight, req, res)
|
||||
fmt.Printf("listen-finalize-block: block-height=%d req=%v res=%v", a.BlockHeight, req, res)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,52 +17,18 @@ type GRPCClient struct {
|
||||
client ABCIListenerServiceClient
|
||||
}
|
||||
|
||||
// ListenBeginBlock listens to begin block request and responses.
|
||||
// In addition, it retrieves a types.Context from a context.Context instance.
|
||||
// It panics if a types.Context was not properly attached.
|
||||
// When the node is configured to stop on listening errors,
|
||||
// it will terminate immediately and exit with a non-zero code.
|
||||
func (m *GRPCClient) ListenBeginBlock(goCtx context.Context, req abci.RequestBeginBlock, res abci.ResponseBeginBlock) error {
|
||||
ctx := goCtx.(storetypes.Context)
|
||||
sm := ctx.StreamingManager()
|
||||
request := &ListenBeginBlockRequest{Req: &req, Res: &res}
|
||||
_, err := m.client.ListenBeginBlock(goCtx, request)
|
||||
if err != nil && sm.StopNodeOnErr {
|
||||
ctx.Logger().Error("BeginBlock listening hook failed", "height", ctx.BlockHeight(), "err", err)
|
||||
cleanupAndExit()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ListenEndBlock listens to end block request and responses.
|
||||
// In addition, it retrieves a types.Context from a context.Context instance.
|
||||
// It panics if a types.Context was not properly attached.
|
||||
// When the node is configured to stop on listening errors,
|
||||
// it will terminate immediately and exit with a non-zero code.
|
||||
func (m *GRPCClient) ListenEndBlock(goCtx context.Context, req abci.RequestEndBlock, res abci.ResponseEndBlock) error {
|
||||
func (m *GRPCClient) ListenFinalizeBlock(goCtx context.Context, req abci.RequestFinalizeBlock, res abci.ResponseFinalizeBlock) error {
|
||||
ctx := goCtx.(storetypes.Context)
|
||||
sm := ctx.StreamingManager()
|
||||
request := &ListenEndBlockRequest{Req: &req, Res: &res}
|
||||
_, err := m.client.ListenEndBlock(goCtx, request)
|
||||
request := &ListenFinalizeBlockRequest{Req: &req, Res: &res}
|
||||
_, err := m.client.ListenFinalizeBlock(goCtx, request)
|
||||
if err != nil && sm.StopNodeOnErr {
|
||||
ctx.Logger().Error("EndBlock listening hook failed", "height", ctx.BlockHeight(), "err", err)
|
||||
cleanupAndExit()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ListenDeliverTx listens to deliver tx request and responses.
|
||||
// In addition, it retrieves a types.Context from a context.Context instance.
|
||||
// It panics if a types.Context was not properly attached.
|
||||
// When the node is configured to stop on listening errors,
|
||||
// it will terminate immediately and exit with a non-zero code.
|
||||
func (m *GRPCClient) ListenDeliverTx(goCtx context.Context, req abci.RequestDeliverTx, res abci.ResponseDeliverTx) error {
|
||||
ctx := goCtx.(storetypes.Context)
|
||||
sm := ctx.StreamingManager()
|
||||
request := &ListenDeliverTxRequest{BlockHeight: ctx.BlockHeight(), Req: &req, Res: &res}
|
||||
_, err := m.client.ListenDeliverTx(goCtx, request)
|
||||
if err != nil && sm.StopNodeOnErr {
|
||||
ctx.Logger().Error("DeliverTx listening hook failed", "height", ctx.BlockHeight(), "err", err)
|
||||
ctx.Logger().Error("FinalizeBlock listening hook failed", "height", ctx.BlockHeight(), "err", err)
|
||||
cleanupAndExit()
|
||||
}
|
||||
return err
|
||||
@@ -98,25 +64,11 @@ type GRPCServer struct {
|
||||
Impl storetypes.ABCIListener
|
||||
}
|
||||
|
||||
func (m GRPCServer) ListenBeginBlock(ctx context.Context, request *ListenBeginBlockRequest) (*ListenBeginBlockResponse, error) {
|
||||
if err := m.Impl.ListenBeginBlock(ctx, *request.Req, *request.Res); err != nil {
|
||||
func (m GRPCServer) ListenFinalizeBlock(ctx context.Context, request *ListenFinalizeBlockRequest) (*ListenFinalizeBlockResponse, error) {
|
||||
if err := m.Impl.ListenFinalizeBlock(ctx, *request.Req, *request.Res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ListenBeginBlockResponse{}, nil
|
||||
}
|
||||
|
||||
func (m GRPCServer) ListenEndBlock(ctx context.Context, request *ListenEndBlockRequest) (*ListenEndBlockResponse, error) {
|
||||
if err := m.Impl.ListenEndBlock(ctx, *request.Req, *request.Res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ListenEndBlockResponse{}, nil
|
||||
}
|
||||
|
||||
func (m GRPCServer) ListenDeliverTx(ctx context.Context, request *ListenDeliverTxRequest) (*ListenDeliverTxResponse, error) {
|
||||
if err := m.Impl.ListenDeliverTx(ctx, *request.Req, *request.Res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ListenDeliverTxResponse{}, nil
|
||||
return &ListenFinalizeBlockResponse{}, nil
|
||||
}
|
||||
|
||||
func (m GRPCServer) ListenCommit(ctx context.Context, request *ListenCommitRequest) (*ListenCommitResponse, error) {
|
||||
|
||||
+97
-936
File diff suppressed because it is too large
Load Diff
@@ -27,13 +27,9 @@ type PluginTestSuite struct {
|
||||
|
||||
workDir string
|
||||
|
||||
beginBlockReq abci.RequestBeginBlock
|
||||
beginBlockRes abci.ResponseBeginBlock
|
||||
endBlockReq abci.RequestEndBlock
|
||||
endBlockRes abci.ResponseEndBlock
|
||||
deliverTxReq abci.RequestDeliverTx
|
||||
deliverTxRes abci.ResponseDeliverTx
|
||||
commitRes abci.ResponseCommit
|
||||
finalizeBlockReq abci.RequestFinalizeBlock
|
||||
finalizeBlockRes abci.ResponseFinalizeBlock
|
||||
commitRes abci.ResponseCommit
|
||||
|
||||
changeSet []*storetypes.StoreKVPair
|
||||
}
|
||||
@@ -71,33 +67,28 @@ func (s *PluginTestSuite) SetupTest() {
|
||||
s.loggerCtx = NewMockContext(header, logger, streamingService)
|
||||
|
||||
// test abci message types
|
||||
s.beginBlockReq = abci.RequestBeginBlock{
|
||||
Header: s.loggerCtx.BlockHeader(),
|
||||
ByzantineValidators: []abci.Misbehavior{},
|
||||
Hash: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
LastCommitInfo: abci.CommitInfo{Round: 1, Votes: []abci.VoteInfo{}},
|
||||
|
||||
s.finalizeBlockReq = abci.RequestFinalizeBlock{
|
||||
Height: s.loggerCtx.BlockHeight(),
|
||||
Txs: [][]byte{{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}},
|
||||
Misbehavior: []abci.Misbehavior{},
|
||||
Hash: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
DecidedLastCommit: abci.CommitInfo{},
|
||||
}
|
||||
s.beginBlockRes = abci.ResponseBeginBlock{
|
||||
Events: []abci.Event{{Type: "testEventType1"}},
|
||||
}
|
||||
s.endBlockReq = abci.RequestEndBlock{Height: s.loggerCtx.BlockHeight()}
|
||||
s.endBlockRes = abci.ResponseEndBlock{
|
||||
s.finalizeBlockRes = abci.ResponseFinalizeBlock{
|
||||
Events: []abci.Event{},
|
||||
ConsensusParamUpdates: &tmproto.ConsensusParams{},
|
||||
ValidatorUpdates: []abci.ValidatorUpdate{},
|
||||
}
|
||||
s.deliverTxReq = abci.RequestDeliverTx{
|
||||
Tx: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1},
|
||||
}
|
||||
s.deliverTxRes = abci.ResponseDeliverTx{
|
||||
Events: []abci.Event{},
|
||||
Code: 1,
|
||||
Codespace: "mockCodeSpace",
|
||||
Data: []byte{5, 6, 7, 8},
|
||||
GasUsed: 2,
|
||||
GasWanted: 3,
|
||||
Info: "mockInfo",
|
||||
Log: "mockLog",
|
||||
TxResults: []*abci.ExecTxResult{{
|
||||
Events: []abci.Event{},
|
||||
Code: 1,
|
||||
Codespace: "mockCodeSpace",
|
||||
Data: []byte{5, 6, 7, 8},
|
||||
GasUsed: 2,
|
||||
GasWanted: 3,
|
||||
Info: "mockInfo",
|
||||
Log: "mockLog",
|
||||
}},
|
||||
}
|
||||
s.commitRes = abci.ResponseCommit{}
|
||||
|
||||
@@ -121,17 +112,10 @@ func (s *PluginTestSuite) TestABCIGRPCPlugin() {
|
||||
abciListeners := s.loggerCtx.StreamingManager().ABCIListeners
|
||||
for _, abciListener := range abciListeners {
|
||||
for i := range [50]int{} {
|
||||
err := abciListener.ListenBeginBlock(s.loggerCtx, s.beginBlockReq, s.beginBlockRes)
|
||||
assert.NoError(t, err, "ListenBeginBlock")
|
||||
|
||||
err = abciListener.ListenEndBlock(s.loggerCtx, s.endBlockReq, s.endBlockRes)
|
||||
err := abciListener.ListenFinalizeBlock(s.loggerCtx, s.finalizeBlockReq, s.finalizeBlockRes)
|
||||
assert.NoError(t, err, "ListenEndBlock")
|
||||
|
||||
for range [50]int{} {
|
||||
err = abciListener.ListenDeliverTx(s.loggerCtx, s.deliverTxReq, s.deliverTxRes)
|
||||
assert.NoError(t, err, "ListenDeliverTx")
|
||||
}
|
||||
|
||||
err = abciListener.ListenCommit(s.loggerCtx, s.commitRes, s.changeSet)
|
||||
assert.NoError(t, err, "ListenCommit")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user