github.com/MetalBlockchain/metalgo@v1.11.9/snow/choices/decidable.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package choices
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/MetalBlockchain/metalgo/ids"
    10  )
    11  
    12  // Decidable represents element that can be decided.
    13  //
    14  // Decidable objects are typically thought of as either transactions, blocks, or
    15  // vertices.
    16  type Decidable interface {
    17  	// ID returns a unique ID for this element.
    18  	//
    19  	// Typically, this is implemented by using a cryptographic hash of a
    20  	// binary representation of this element. An element should return the same
    21  	// IDs upon repeated calls.
    22  	ID() ids.ID
    23  
    24  	// Accept this element.
    25  	//
    26  	// This element will be accepted by every correct node in the network.
    27  	// All subsequent Status calls return Accepted.
    28  	Accept(context.Context) error
    29  
    30  	// Reject this element.
    31  	//
    32  	// This element will not be accepted by any correct node in the network.
    33  	// All subsequent Status calls return Rejected.
    34  	Reject(context.Context) error
    35  
    36  	// Status returns this element's current status.
    37  	//
    38  	// If Accept has been called on an element with this ID, Accepted should be
    39  	// returned. Similarly, if Reject has been called on an element with this
    40  	// ID, Rejected should be returned. If the contents of this element are
    41  	// unknown, then Unknown should be returned. Otherwise, Processing should be
    42  	// returned.
    43  	//
    44  	// TODO: Consider allowing Status to return an error.
    45  	Status() Status
    46  }