-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(server/v2): Update prepare & process proposal #21237
Changes from 3 commits
faf5335
f6b5f43
532edc8
96171df
c734809
53fafa8
9d725d4
5841d3b
5262b84
6856241
1075d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,8 +315,12 @@ func (c *Consensus[T]) PrepareProposal( | |
return nil, errors.New("PrepareProposal called with invalid height") | ||
} | ||
|
||
decodedTxs := make([]T, len(req.Txs)) | ||
for i, tx := range req.Txs { | ||
if c.prepareProposalHandler == nil { | ||
return nil, errors.New("no prepare proposal function was set") | ||
} | ||
|
||
var decodedTxs []T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should preallocate here as we know the length There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought the same but we skip undecodable txs, so the index would then be nil There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only case we can't decode is if it's a vote exetension or some other data type of the state machine right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be yeah There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to remove the decoding part and make it part of the handler. it wont work this way, and requiring users to modify the decoder feels weird There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense to move it to handler. |
||
for _, tx := range req.Txs { | ||
decTx, err := c.txCodec.Decode(tx) | ||
if err != nil { | ||
// TODO: vote extension meta data as a custom type to avoid possibly accepting invalid txs | ||
|
@@ -325,7 +329,7 @@ func (c *Consensus[T]) PrepareProposal( | |
continue | ||
} | ||
|
||
decodedTxs[i] = decTx | ||
decodedTxs = append(decodedTxs, decTx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont believe this is correct. in the case of vote extensions we will not be able to decode the txs meaning we will always remove it from the block. This should happen in the handler instead of here. This is how its handled in abci. |
||
} | ||
|
||
ciCtx := contextWithCometInfo(ctx, comet.Info{ | ||
|
@@ -356,7 +360,15 @@ func (c *Consensus[T]) ProcessProposal( | |
ctx context.Context, | ||
req *abciproto.ProcessProposalRequest, | ||
) (*abciproto.ProcessProposalResponse, error) { | ||
decodedTxs := make([]T, len(req.Txs)) | ||
if req.Height < 1 { | ||
return nil, errors.New("ProcessProposal called with invalid height") | ||
} | ||
|
||
if c.processProposalHandler == nil { | ||
return nil, errors.New("no process proposal function was set") | ||
} | ||
|
||
var decodedTxs []T | ||
for _, tx := range req.Txs { | ||
decTx, err := c.txCodec.Decode(tx) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this fail at app build time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you don't pass anything to the comet server, we use the default options (no op handlers).
so to get this you would have to purposely pass nil. as we don't want to make those mandatory, making it fail at compile time isn't best.