refactor: add-vote operation#558
Conversation
…e responsibility, use 2 sets (prevote and precommit) to process adding of vote
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
…o refactor-add-vote-operation # Conflicts: # internal/consensus/state_add_vote_cmd.go
shotonoff
left a comment
There was a problem hiding this comment.
please check the answers and changes according to the feedback
| } | ||
| added, err := stateData.LastPrecommits.AddVote(vote) | ||
| if !added { | ||
| logger.Debug("vote not added to last precommits", logKeyValsWithError([]any(nil), err)...) |
There was a problem hiding this comment.
looks like overkill
| logger.Debug("vote not added to last precommits", logKeyValsWithError([]any(nil), err)...) | |
| logger.Debug("vote not added to last precommits", "error", err) |
There was a problem hiding this comment.
No, the idea is to add an error only if the error is not nil
your patch adds the error with nil value.
the empty (or nil) error leads difficult filtering the logs by error
There was a problem hiding this comment.
maybe add sme feature to our log package? to automatically skip error if it's nil. Like logger.Err(err).Debug()? (can be separate PR, to not increase scope of this one).
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
Co-authored-by: lklimek <842586+lklimek@users.noreply.github.com>
…o refactor-add-vote-operation
shotonoff
left a comment
There was a problem hiding this comment.
applied changes by PR
| } | ||
| added, err := stateData.LastPrecommits.AddVote(vote) | ||
| if !added { | ||
| logger.Debug("vote not added to last precommits", logKeyValsWithError([]any(nil), err)...) |
There was a problem hiding this comment.
No, the idea is to add an error only if the error is not nil
your patch adds the error with nil value.
the empty (or nil) error leads difficult filtering the logs by error
| } | ||
| added, err := stateData.LastPrecommits.AddVote(vote) | ||
| if !added { | ||
| logger.Debug("vote not added to last precommits", logKeyValsWithError([]any(nil), err)...) |
There was a problem hiding this comment.
maybe add sme feature to our log package? to automatically skip error if it's nil. Like logger.Err(err).Debug()? (can be separate PR, to not increase scope of this one).
* refactor: add sendMessage method to consensus.State * refactor: modify sendMessage * refactor: decompose WAL interface on a few small * refactor: refactor an approach of message consuming for consensus state component * refactor: add graceful stop for chanMsgReader * refactor: consensus state priv-validator * refactor: huge refactoring of consensus state, separate each state change task as a separate command, similar to state machine implementation * refactor: add a stop function to a consensus to be able to stop receiveRoutine by a condition * fix: remove block validating in finalizeCommit * refactor: define Executor and VoteExtender interfaces, add executor mock, refactor return statement of Executor.ExtendVote * test: add TestChanQueue, TestChanMsgSender, TestChanMsgReader * test: generate PrivValidator mock * refactor: move sending stats data from message handler * refactor: add-vote operation (#558) * refactor: separate TryAddVote.addVote logic on small function with one responsibility, use 2 sets (prevote and precommit) to process adding of vote * refactor: replace peerID on proTxHash for peer catchup rounds in HeightVoteSet component * fix: remove unused errors and StateData.validateVote * refactor: EventSwitch implementation (#569) * refactor: package lib/events rename on eventemitter and EventSwitch rename on EventEmitter, change EventEmitter api * fix: add PeerManager.Unsubscribe method (#594) * refactor: set and decide proposal operations (#565) * refactor: set and decide proposal operations move to the separated component proposaler * refactor: consensus peer gossip mechanism (#551) * refactor: separate a gossip logic on implementation and a standard way of iterative handling a gossip condition * chore: remove unless commented line * refactor: remove custom "peerSyncErr" error * refactor: add Gossiper interface, generate Gossiper mock struct, add unit test to queryMaj23GossipHandler * refactor: peerGossipWorker implements service.Service * refactor: blocksync module is refactored on using worker-pool * test: replace custom assertError on tmrequire.Error * refactor: add Now function into flowrate package, to obtain the current time * fix: TestHandshakeErrorsIfAppReturnsWrongAppHash in replay_test.go * refactor: move the logic wait-for blockchain sync from reactor to BlockPool * fix: TestReactor_SyncTime * test: change timing for test TestBlockPoolBasic * chore: replace clock on clockwork * refactor: replace reactor's consuming on separate consumer function in Channel, rename SetPeerRange on AddPeer * test: add TestConsumeError * chore: remove unused mustHexToBytes * chore: add examples in promise/example_test.go and docs comments * chore: change a package for MockValidatorSet from types on factory * Update internal/blocksync/channel.go * feat: create p2p/client package (#602) * refactor: add internal/p2p/client implementation * refactor: change blocksync module to support p2p client * test: fix TestMakeHTTPDialerURL (#605) * refactor: rename RandomNode on AnyNode as more specific name * refactor: introduce p2p client in mempool module (#606)
Issue being fixed or feature implemented
Implementation of
AddVoteoperation has a bad design that leads in difficult reading and understanding this process.In a discussion with @lklimek, we decided that this function must be refactored to make this process clear and maintainable
What was done?
The
addVoteoperation was separated on several independent functions, which are used for prevote and precommit setsA received vote is processed by the vote-set according to
Vote.TypeKey design changes
there are 2 new types:
addVoteFunc functhis type must be implemented by each function to be able to use in a add-vote setaddVoteMwFuncthis type must be implemented by middleware functionThe idea is to use middleware approach (or chain responsibility) where
Voting has been split between these functions:
addVoteToLastPrecommitMw- either add a vote to last-precommit vote-set and break processing or move to the next itemaddVoteValidateVoteMw- validate vote before to add and if a vote is valid to move to the next itemaddVoteToVoteSet- this is the main function, it only has the logic of adding votesaddVoteUpdateValidBlockMw- updates state-data after successful adding vote and move to the next itemaddVoteDispatchPrevoteMw- after successful added vote, executes the transition based on vote state for prevote and move to the next itemaddVoteDispatchPrecommitMw- execute another transition based on vote state for precommitaddVoteVerifyVoteExtensionMw- before adding vote verify vote extensions if a vote is precommitaddVoteStatsMw- sendmsgInfomessage to stats-queueaddVoteErrorMw- correct handle erroraddVoteLoggingMw- write logs before and after adding the voteHow Has This Been Tested?
Unit-test / E2E test
Added a few new unit-tests for new code, need to add more
Breaking Changes
N/A
Checklist:
For repository code-owners and collaborators only