Skip to content

evidence: buffer evidence from consensus#5890

Merged
cmwaters merged 4 commits intomasterfrom
callum/evidence-from-consensus
Jan 12, 2021
Merged

evidence: buffer evidence from consensus#5890
cmwaters merged 4 commits intomasterfrom
callum/evidence-from-consensus

Conversation

@cmwaters
Copy link
Copy Markdown
Contributor

Description

Evidence coming from consensus is stored in a temporary buffer before being flushed to the evidence pool and thus halted until the voting in the height of the evidence is finished before being broadcasted and proposed. This avoids the issue of some nodes verifying and proposing evidence at a height where the block hasn't been committed yet which could cause those peers who never saw the double votes to panic.

@cmwaters cmwaters added this to the 0.34.2 milestone Jan 12, 2021
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 12, 2021

Codecov Report

Merging #5890 (c329028) into master (f05788e) will increase coverage by 0.00%.
The diff coverage is 85.00%.

@@           Coverage Diff           @@
##           master    #5890   +/-   ##
=======================================
  Coverage   59.90%   59.91%           
=======================================
  Files         269      269           
  Lines       24544    24550    +6     
=======================================
+ Hits        14703    14709    +6     
  Misses       8244     8244           
  Partials     1597     1597           
Impacted Files Coverage Δ
evidence/pool.go 65.60% <85.00%> (+0.43%) ⬆️
crypto/sr25519/pubkey.go 43.47% <0.00%> (-8.70%) ⬇️
p2p/switch.go 63.88% <0.00%> (-2.09%) ⬇️
libs/clist/clist.go 67.25% <0.00%> (-1.76%) ⬇️
statesync/snapshots.go 91.59% <0.00%> (-1.69%) ⬇️
mempool/reactor.go 80.83% <0.00%> (-1.67%) ⬇️
blockchain/v0/pool.go 78.32% <0.00%> (-1.53%) ⬇️
statesync/syncer.go 79.60% <0.00%> (-0.81%) ⬇️
mempool/clist_mempool.go 80.57% <0.00%> (-0.72%) ⬇️
proxy/multi_app_conn.go 48.05% <0.00%> (ø)
... and 6 more

Copy link
Copy Markdown
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

changelog entry is missing

Comment thread evidence/pool.go
func (evpool *Pool) flushConsensusBuffer() {
for _, ev := range evpool.consensusBuffer {
if err := evpool.addPendingEvidence(ev); err != nil {
evpool.logger.Error("failed to flush evidence from consensus buffer to pending list: %w", err)
Copy link
Copy Markdown
Contributor

@melekes melekes Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
evpool.logger.Error("failed to flush evidence from consensus buffer to pending list: %w", err)
evpool.logger.Error("failed to flush evidence from consensus buffer to pending list: %w", err)
continue

?

Comment thread evidence/pool.go
evpool.evidenceList.PushBack(ev)
}
// reset consensus buffer
evpool.consensusBuffer = make([]types.Evidence, 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any potential data races?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are at different stages of consensus I believe but it might pay to put a mutex on the slice just in case

Comment thread evidence/pool.go Outdated
pruningHeight int64
pruningTime time.Time

consensusBuffer []types.Evidence
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a comment here too?

@cmwaters cmwaters requested a review from tac0turtle as a code owner January 12, 2021 11:19
@cmwaters cmwaters merged commit 956b59a into master Jan 12, 2021
@cmwaters cmwaters deleted the callum/evidence-from-consensus branch January 12, 2021 11:50
tessr pushed a commit that referenced this pull request Jan 12, 2021
Comment thread evidence/pool.go
evpool.state = state
// flushConsensusBuffer moves the evidence produced from consensus into the evidence pool
// and list so that it can be broadcasted and proposed
func (evpool *Pool) flushConsensusBuffer() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would've added a write-lock here instead of using it in Pool#Update. That way, it becomes:

evpool.flushConsensusBuffer()
evpool.updateState(state)

I say this because we have updateState already that does write-locking, but now Pool#Update does it :-/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess this makes sense to avoid someone in the future from using evpool.flushConsensusBuffer() without taking out a lock

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wasn't too sure if the best practice was to create another lock or use the existing lock on state for consensusBuffer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have auxiliary logic (method) that does all the business logic, I believe we should place the lock here. This isn't necessarily critical though 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants