github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowman/snowman_block.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package snowman
     5  
     6  import (
     7  	"github.com/MetalBlockchain/metalgo/ids"
     8  	"github.com/MetalBlockchain/metalgo/snow/consensus/snowball"
     9  )
    10  
    11  // Tracks the state of a snowman block
    12  type snowmanBlock struct {
    13  	t *Topological
    14  
    15  	// block that this node contains. For the genesis, this value will be nil
    16  	blk Block
    17  
    18  	// shouldFalter is set to true if this node, and all its descendants received
    19  	// less than Alpha votes
    20  	shouldFalter bool
    21  
    22  	// sb is the snowball instance used to decide which child is the canonical
    23  	// child of this block. If this node has not had a child issued under it,
    24  	// this value will be nil
    25  	sb snowball.Consensus
    26  
    27  	// children is the set of blocks that have been issued that name this block
    28  	// as their parent. If this node has not had a child issued under it, this value
    29  	// will be nil
    30  	children map[ids.ID]Block
    31  }
    32  
    33  func (n *snowmanBlock) AddChild(child Block) {
    34  	childID := child.ID()
    35  
    36  	// if the snowball instance is nil, this is the first child. So the instance
    37  	// should be initialized.
    38  	if n.sb == nil {
    39  		n.sb = snowball.NewTree(snowball.SnowballFactory, n.t.params, childID)
    40  		n.children = make(map[ids.ID]Block)
    41  	} else {
    42  		n.sb.Add(childID)
    43  	}
    44  
    45  	n.children[childID] = child
    46  }
    47  
    48  func (n *snowmanBlock) Decided() bool {
    49  	// if the block is nil, then this is the genesis which is defined as
    50  	// accepted
    51  	return n.blk == nil || n.blk.Height() <= n.t.lastAcceptedHeight
    52  }