github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowman/consensus.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/api/health" 11 "github.com/MetalBlockchain/metalgo/ids" 12 "github.com/MetalBlockchain/metalgo/snow" 13 "github.com/MetalBlockchain/metalgo/snow/consensus/snowball" 14 "github.com/MetalBlockchain/metalgo/utils/bag" 15 ) 16 17 // Consensus represents a general snowman instance that can be used directly to 18 // process a series of dependent operations. 19 type Consensus interface { 20 health.Checker 21 22 // Takes in the context, snowball parameters, and the last accepted block. 23 Initialize( 24 ctx *snow.ConsensusContext, 25 params snowball.Parameters, 26 lastAcceptedID ids.ID, 27 lastAcceptedHeight uint64, 28 lastAcceptedTime time.Time, 29 ) error 30 31 // Returns the number of blocks processing 32 NumProcessing() int 33 34 // Add a new block. 35 // 36 // Add should not be called multiple times with the same block. 37 // The parent block should either be the last accepted block or processing. 38 // 39 // Returns if a critical error has occurred. 40 Add(Block) error 41 42 // Processing returns true if the block ID is currently processing. 43 Processing(ids.ID) bool 44 45 // IsPreferred returns true if the block ID is preferred. Only the last 46 // accepted block and processing blocks are considered preferred. 47 IsPreferred(ids.ID) bool 48 49 // Returns the ID and height of the last accepted decision. 50 LastAccepted() (ids.ID, uint64) 51 52 // Returns the ID of the tail of the strongly preferred sequence of 53 // decisions. 54 Preference() ids.ID 55 56 // Returns the ID of the strongly preferred decision with the provided 57 // height. Only the last accepted decision and processing decisions are 58 // tracked. 59 PreferenceAtHeight(height uint64) (ids.ID, bool) 60 61 // RecordPoll collects the results of a network poll. Assumes all decisions 62 // have been previously added. Returns if a critical error has occurred. 63 RecordPoll(context.Context, bag.Bag[ids.ID]) error 64 }