Skip to content
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

Remove .Status() from .Accepted() #3124

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions snow/consensus/snowman/snowman_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ package snowman

import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/choices"
"github.com/ava-labs/avalanchego/snow/consensus/snowball"
)

// Tracks the state of a snowman block
type snowmanBlock struct {
// parameters to initialize the snowball instance with
params snowball.Parameters
t *Topological

// block that this node contains. For the genesis, this value will be nil
blk Block
Expand All @@ -38,7 +36,7 @@ func (n *snowmanBlock) AddChild(child Block) {
// if the snowball instance is nil, this is the first child. So the instance
// should be initialized.
if n.sb == nil {
n.sb = snowball.NewTree(snowball.SnowballFactory, n.params, childID)
n.sb = snowball.NewTree(snowball.SnowballFactory, n.t.params, childID)
n.children = make(map[ids.ID]Block)
} else {
n.sb.Add(childID)
Expand All @@ -47,11 +45,8 @@ func (n *snowmanBlock) AddChild(child Block) {
n.children[childID] = child
}

func (n *snowmanBlock) Accepted() bool {
func (n *snowmanBlock) Decided() bool {
// if the block is nil, then this is the genesis which is defined as
// accepted
if n.blk == nil {
return true
}
return n.blk.Status() == choices.Accepted
return n.blk == nil || n.blk.Height() <= n.t.lastAcceptedHeight
}
14 changes: 7 additions & 7 deletions snow/consensus/snowman/topological.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (ts *Topological) Initialize(
ts.lastAcceptedID = lastAcceptedID
ts.lastAcceptedHeight = lastAcceptedHeight
ts.blocks = map[ids.ID]*snowmanBlock{
lastAcceptedID: {params: ts.params},
lastAcceptedID: {t: ts},
}
ts.preferredHeights = make(map[uint64]ids.ID)
ts.preference = lastAcceptedID
Expand Down Expand Up @@ -163,8 +163,8 @@ func (ts *Topological) Add(blk Block) error {
// add the block as a child of its parent, and add the block to the tree
parentNode.AddChild(blk)
ts.blocks[blkID] = &snowmanBlock{
params: ts.params,
blk: blk,
t: ts,
blk: blk,
}

// If we are extending the preference, this is the new preference
Expand Down Expand Up @@ -289,7 +289,7 @@ func (ts *Topological) RecordPoll(ctx context.Context, voteBag bag.Bag[ids.ID])

// Runtime = |live set| ; Space = Constant
// Traverse from the preferred ID to the last accepted ancestor.
for block := startBlock; !block.Accepted(); {
for block := startBlock; !block.Decided(); {
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
blkID := block.blk.ID()
ts.preferredIDs.Add(blkID)
ts.preferredHeights[block.blk.Height()] = blkID
Expand Down Expand Up @@ -360,7 +360,7 @@ func (ts *Topological) calculateInDegree(votes bag.Bag[ids.ID]) {
}

// If the vote is for the last accepted block, the vote is dropped
if votedBlock.Accepted() {
if votedBlock.Decided() {
continue
}

Expand All @@ -384,7 +384,7 @@ func (ts *Topological) calculateInDegree(votes bag.Bag[ids.ID]) {

// iterate through all the block's ancestors and set up the inDegrees of
// the blocks
for n := ts.blocks[parentID]; !n.Accepted(); n = ts.blocks[parentID] {
for n := ts.blocks[parentID]; !n.Decided(); n = ts.blocks[parentID] {
parentID = n.blk.Parent()

// Increase the inDegree by one
Expand Down Expand Up @@ -428,7 +428,7 @@ func (ts *Topological) pushVotes() []votes {

// If the block is accepted, then we don't need to push votes to the
// parent block
if block.Accepted() {
if block.Decided() {
continue
}

Expand Down
Loading