github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/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  	"context"
     8  	"time"
     9  
    10  	"github.com/MetalBlockchain/metalgo/ids"
    11  	"github.com/MetalBlockchain/metalgo/snow/choices"
    12  )
    13  
    14  // Block is a possible decision that dictates the next canonical block.
    15  //
    16  // Blocks are guaranteed to be Verified, Accepted, and Rejected in topological
    17  // order. Specifically, if Verify is called, then the parent has already been
    18  // verified. If Accept is called, then the parent has already been accepted. If
    19  // Reject is called, the parent has already been accepted or rejected.
    20  //
    21  // If the status of the block is Unknown, ID is assumed to be able to be called.
    22  // If the status of the block is Accepted or Rejected; Parent, Verify, Accept,
    23  // and Reject will never be called.
    24  type Block interface {
    25  	choices.Decidable
    26  
    27  	// Parent returns the ID of this block's parent.
    28  	Parent() ids.ID
    29  
    30  	// Verify that the state transition this block would make if accepted is
    31  	// valid. If the state transition is invalid, a non-nil error should be
    32  	// returned.
    33  	//
    34  	// It is guaranteed that the Parent has been successfully verified.
    35  	//
    36  	// If nil is returned, it is guaranteed that either Accept or Reject will be
    37  	// called on this block, unless the VM is shut down.
    38  	Verify(context.Context) error
    39  
    40  	// Bytes returns the binary representation of this block.
    41  	//
    42  	// This is used for sending blocks to peers. The bytes should be able to be
    43  	// parsed into the same block on another node.
    44  	Bytes() []byte
    45  
    46  	// Height returns the height of this block in the chain.
    47  	Height() uint64
    48  
    49  	// Time this block was proposed at. This value should be consistent across
    50  	// all nodes. If this block hasn't been successfully verified, any value can
    51  	// be returned. If this block is the last accepted block, the timestamp must
    52  	// be returned correctly. Otherwise, accepted blocks can return any value.
    53  	Timestamp() time.Time
    54  }