-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backport: v0.7.1 into v0.8-dev (#361)
* Update golangci-lint-action and golang-ci versions. Also specify Go toolchain version in actions (now required). (cherry picked from commit 14461339f43029e1cfedf799fa8a60ffcf1f5b69) * fix(consensus): network stuck due to outdated proposal block (#327) * fix(consensus): network stuck due to outdated proposal block * refactor(consensus): cleanup TestStateProposalTime * fix(xchacha20poly1305_test): (*testing.common).Errorf does not support error-wrapping directive %w * fix(consensus): fix race condition * chore(consensus): apply peer review feedback * fix: don't process WAL logs for old rounds (#331) * feat: add the implementation of WAL iterator with a feature skipping messages till the final round * feat: change order and name of walIter fields * feat: stop iterating if reader returns error * feat: remove checking on allowed message types * feat: improve was_iter_test.go * refactor: modify by go-lint feedback * refactor: remove useless expected length * chore: disable lint for a non-critical line in a test * chore(release): update changelog and bump version to 0.7.1-dev.1 (#330) * chore(release): update changelog generation config * chore(release): update changelog and version to 0.7.1-dev.1 * build(release): implement full release workflow in the release script (#332) (#345) * chore(release): update changelog generation config * build(release): improve version release script * feat(release): release script now creates GitHub release * Update golangci-lint-action and golang-ci versions. Also specify Go toolchain version in actions (now required). (cherry picked from commit 14461339f43029e1cfedf799fa8a60ffcf1f5b69) * fix(consensus): network stuck due to outdated proposal block (#327) * fix(consensus): network stuck due to outdated proposal block * refactor(consensus): cleanup TestStateProposalTime * fix(xchacha20poly1305_test): (*testing.common).Errorf does not support error-wrapping directive %w * fix(consensus): fix race condition * chore(consensus): apply peer review feedback * fix: don't process WAL logs for old rounds (#331) * feat: add the implementation of WAL iterator with a feature skipping messages till the final round * feat: change order and name of walIter fields * feat: stop iterating if reader returns error * feat: remove checking on allowed message types * feat: improve was_iter_test.go * refactor: modify by go-lint feedback * refactor: remove useless expected length * chore: disable lint for a non-critical line in a test * chore(release): update changelog and bump version to 0.7.1-dev.1 (#330) * chore(release): update changelog generation config * chore(release): update changelog and version to 0.7.1-dev.1 * build(release): implement full release workflow in the release script (#332) (#345) * chore(release): update changelog generation config * build(release): improve version release script * feat(release): release script now creates GitHub release * chore(release): update changelog and version to 0.7.1 * chore: if the tenderdash source code is not tracked by git then cloning "develop_0.1" branch as fallback scenario to build a project (#355) * fix: remove duplicate method BlockID Co-authored-by: M. J. Fromberger <[email protected]> Co-authored-by: lklimek <[email protected]>
- Loading branch information
1 parent
5faeef9
commit c58b60d
Showing
9 changed files
with
427 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package consensus | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/tendermint/tendermint/types" | ||
) | ||
|
||
type walReader interface { | ||
Decode() (*TimedWALMessage, error) | ||
} | ||
|
||
type walIter struct { | ||
reader walReader | ||
curHeight int64 | ||
curRound int32 | ||
queue []*TimedWALMessage | ||
hold []*TimedWALMessage | ||
msg *TimedWALMessage | ||
err error | ||
} | ||
|
||
func newWalIter(reader walReader) *walIter { | ||
return &walIter{ | ||
reader: reader, | ||
} | ||
} | ||
|
||
// Value takes a top element from a queue, otherwise returns nil if the queue is empty | ||
func (i *walIter) Value() *TimedWALMessage { | ||
if len(i.queue) == 0 { | ||
return nil | ||
} | ||
msg := i.queue[0] | ||
i.queue = i.queue[1:] | ||
return msg | ||
} | ||
|
||
// Next reads a next message from WAL, every message holds until reach a next height | ||
// if the read message is Propose with the "round" greater than previous, then held messages are flush | ||
func (i *walIter) Next() bool { | ||
if len(i.queue) > 0 { | ||
return true | ||
} | ||
if i.err != nil { | ||
return false | ||
} | ||
for len(i.queue) == 0 && i.readMsg() { | ||
if !i.processMsg(i.msg) { | ||
return false | ||
} | ||
i.hold = append(i.hold, i.msg) | ||
} | ||
if len(i.queue) == 0 { | ||
i.queue = i.hold | ||
} | ||
return len(i.queue) > 0 | ||
} | ||
|
||
// Err returns an error if got the error is not io.EOF otherwise returns nil | ||
func (i *walIter) Err() error { | ||
if i.err == io.EOF { | ||
return nil | ||
} | ||
return i.err | ||
} | ||
|
||
func (i *walIter) readMsg() bool { | ||
if i.err == io.EOF { | ||
return false | ||
} | ||
i.msg, i.err = i.reader.Decode() | ||
if i.err == io.EOF { | ||
return false | ||
} | ||
if i.err != nil { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (i *walIter) processMsg(msg *TimedWALMessage) bool { | ||
m, ok := msg.Msg.(msgInfo) | ||
if !ok { | ||
return true | ||
} | ||
mi, ok := m.Msg.(*ProposalMessage) | ||
if ok { | ||
i.processProposal(mi.Proposal) | ||
} | ||
return true | ||
} | ||
|
||
func (i *walIter) processProposal(p *types.Proposal) { | ||
if p.Height == i.curHeight && i.curRound < p.Round { | ||
i.hold = nil | ||
i.curRound = p.Round | ||
} | ||
if p.Height > i.curHeight { | ||
i.curHeight = p.Height | ||
i.curRound = p.Round | ||
i.queue = i.hold | ||
i.hold = nil | ||
} | ||
} |
Oops, something went wrong.