github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/snowman/issuer.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  
     9  	"github.com/prometheus/client_golang/prometheus"
    10  
    11  	"github.com/MetalBlockchain/metalgo/ids"
    12  	"github.com/MetalBlockchain/metalgo/snow/consensus/snowman"
    13  	"github.com/MetalBlockchain/metalgo/snow/engine/snowman/job"
    14  )
    15  
    16  var _ job.Job[ids.ID] = (*issuer)(nil)
    17  
    18  // issuer issues [blk] into to consensus after its dependencies are met.
    19  type issuer struct {
    20  	t            *Transitive
    21  	nodeID       ids.NodeID // nodeID of the peer that provided this block
    22  	blk          snowman.Block
    23  	push         bool
    24  	issuedMetric prometheus.Counter
    25  }
    26  
    27  func (i *issuer) Execute(ctx context.Context, _ []ids.ID, abandoned []ids.ID) error {
    28  	if len(abandoned) == 0 {
    29  		// If the parent block wasn't abandoned, this block can be issued.
    30  		return i.t.deliver(ctx, i.nodeID, i.blk, i.push, i.issuedMetric)
    31  	}
    32  
    33  	// If the parent block was abandoned, this block should be abandoned as
    34  	// well.
    35  	blkID := i.blk.ID()
    36  	delete(i.t.pending, blkID)
    37  	i.t.addToNonVerifieds(i.blk)
    38  	return i.t.blocked.Abandon(ctx, blkID)
    39  }