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

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package snow
     5  
     6  import (
     7  	"sync"
     8  
     9  	"github.com/prometheus/client_golang/prometheus"
    10  
    11  	"github.com/MetalBlockchain/metalgo/api/keystore"
    12  	"github.com/MetalBlockchain/metalgo/api/metrics"
    13  	"github.com/MetalBlockchain/metalgo/chains/atomic"
    14  	"github.com/MetalBlockchain/metalgo/ids"
    15  	"github.com/MetalBlockchain/metalgo/snow/validators"
    16  	"github.com/MetalBlockchain/metalgo/utils"
    17  	"github.com/MetalBlockchain/metalgo/utils/crypto/bls"
    18  	"github.com/MetalBlockchain/metalgo/utils/logging"
    19  	"github.com/MetalBlockchain/metalgo/vms/platformvm/warp"
    20  )
    21  
    22  // ContextInitializable represents an object that can be initialized
    23  // given a *Context object
    24  type ContextInitializable interface {
    25  	// InitCtx initializes an object provided a *Context object
    26  	InitCtx(ctx *Context)
    27  }
    28  
    29  // Context is information about the current execution.
    30  // [NetworkID] is the ID of the network this context exists within.
    31  // [ChainID] is the ID of the chain this context exists within.
    32  // [NodeID] is the ID of this node
    33  type Context struct {
    34  	NetworkID uint32
    35  	SubnetID  ids.ID
    36  	ChainID   ids.ID
    37  	NodeID    ids.NodeID
    38  	PublicKey *bls.PublicKey
    39  
    40  	XChainID    ids.ID
    41  	CChainID    ids.ID
    42  	AVAXAssetID ids.ID
    43  
    44  	Log          logging.Logger
    45  	Lock         sync.RWMutex
    46  	Keystore     keystore.BlockchainKeystore
    47  	SharedMemory atomic.SharedMemory
    48  	BCLookup     ids.AliaserReader
    49  	Metrics      metrics.MultiGatherer
    50  
    51  	WarpSigner warp.Signer
    52  
    53  	// snowman++ attributes
    54  	ValidatorState validators.State // interface for P-Chain validators
    55  	// Chain-specific directory where arbitrary data can be written
    56  	ChainDataDir string
    57  }
    58  
    59  // Expose gatherer interface for unit testing.
    60  type Registerer interface {
    61  	prometheus.Registerer
    62  	prometheus.Gatherer
    63  }
    64  
    65  type ConsensusContext struct {
    66  	*Context
    67  
    68  	// PrimaryAlias is the primary alias of the chain this context exists
    69  	// within.
    70  	PrimaryAlias string
    71  
    72  	// Registers all consensus metrics.
    73  	Registerer Registerer
    74  
    75  	// BlockAcceptor is the callback that will be fired whenever a VM is
    76  	// notified that their block was accepted.
    77  	BlockAcceptor Acceptor
    78  
    79  	// TxAcceptor is the callback that will be fired whenever a VM is notified
    80  	// that their transaction was accepted.
    81  	TxAcceptor Acceptor
    82  
    83  	// VertexAcceptor is the callback that will be fired whenever a vertex was
    84  	// accepted.
    85  	VertexAcceptor Acceptor
    86  
    87  	// State indicates the current state of this consensus instance.
    88  	State utils.Atomic[EngineState]
    89  
    90  	// True iff this chain is executing transactions as part of bootstrapping.
    91  	Executing utils.Atomic[bool]
    92  
    93  	// True iff this chain is currently state-syncing
    94  	StateSyncing utils.Atomic[bool]
    95  }