fix build

This commit is contained in:
Sergio Mena
2022-11-28 00:00:59 +01:00
parent ee3048f98f
commit c3cb29c67b
2 changed files with 27 additions and 15 deletions

View File

@@ -350,7 +350,7 @@ func (app *Application) PrepareProposal(
"extTxLen", len(extTx),
)
}
return abci.ResponsePrepareProposal{Txs: txs}
return &abci.ResponsePrepareProposal{Txs: txs}, nil
}
// None of the transactions are modified by this application.
txs := make([][]byte, 0, len(req.Txs))
@@ -380,7 +380,7 @@ func (app *Application) ProcessProposal(_ context.Context, req *abci.RequestProc
_, err := strconv.Atoi(v)
if err != nil {
app.logger.Error("malformed vote extension transaction", k, v, "err", err)
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}
}
}
@@ -399,7 +399,7 @@ func (app *Application) ProcessProposal(_ context.Context, req *abci.RequestProc
// a new transaction will be proposed that updates a special value in the
// key/value store ("extensionSum") with the sum of all of the numbers collected
// from the vote extensions.
func (app *Application) ExtendVote(req abci.RequestExtendVote) abci.ResponseExtendVote {
func (app *Application) ExtendVote(_ context.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
// We ignore any requests for vote extensions that don't match our expected
// next height.
if req.Height != int64(app.state.Height)+1 {
@@ -408,7 +408,7 @@ func (app *Application) ExtendVote(req abci.RequestExtendVote) abci.ResponseExte
"expectedHeight", app.state.Height+1,
"requestHeight", req.Height,
)
return abci.ResponseExtendVote{}
return &abci.ResponseExtendVote{}, nil
}
ext := make([]byte, binary.MaxVarintLen64)
// We don't care that these values are generated by a weak random number
@@ -417,20 +417,20 @@ func (app *Application) ExtendVote(req abci.RequestExtendVote) abci.ResponseExte
num := rand.Int63n(voteExtensionMaxVal)
extLen := binary.PutVarint(ext, num)
app.logger.Info("generated vote extension", "num", num, "ext", fmt.Sprintf("%x", ext[:extLen]), "state.Height", app.state.Height)
return abci.ResponseExtendVote{
return &abci.ResponseExtendVote{
VoteExtension: ext[:extLen],
}
}, nil
}
// VerifyVoteExtension simply validates vote extensions from other validators
// without doing anything about them. In this case, it just makes sure that the
// vote extension is a well-formed integer value.
func (app *Application) VerifyVoteExtension(req abci.RequestVerifyVoteExtension) abci.ResponseVerifyVoteExtension {
func (app *Application) VerifyVoteExtension(_ context.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
// We allow vote extensions to be optional
if len(req.VoteExtension) == 0 {
return abci.ResponseVerifyVoteExtension{
return &abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
}
}, nil
}
if req.Height != int64(app.state.Height)+1 {
app.logger.Error(
@@ -438,22 +438,22 @@ func (app *Application) VerifyVoteExtension(req abci.RequestVerifyVoteExtension)
"expectedHeight", app.state.Height,
"requestHeight", req.Height,
)
return abci.ResponseVerifyVoteExtension{
return &abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_REJECT,
}
}, nil
}
num, err := parseVoteExtension(req.VoteExtension)
if err != nil {
app.logger.Error("failed to verify vote extension", "req", req, "err", err)
return abci.ResponseVerifyVoteExtension{
return &abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_REJECT,
}
}, nil
}
app.logger.Info("verified vote extension value", "req", req, "num", num)
return abci.ResponseVerifyVoteExtension{
return &abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,
}
}, nil
}
func (app *Application) Rollback() error {

View File

@@ -59,6 +59,18 @@ func (app *SyncApplication) ProcessProposal(ctx context.Context, req *abci.Reque
return app.app.ProcessProposal(ctx, req)
}
func (app *SyncApplication) ExtendVote(ctx context.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
app.mtx.Lock()
defer app.mtx.Unlock()
return app.app.ExtendVote(ctx, req)
}
func (app *SyncApplication) VerifyVoteExtension(ctx context.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
app.mtx.Lock()
defer app.mtx.Unlock()
return app.app.VerifyVoteExtension(ctx, req)
}
func (app *SyncApplication) FinalizeBlock(ctx context.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
app.mtx.Lock()
defer app.mtx.Unlock()