github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/gossip/emitter/world.go (about)

     1  package emitter
     2  
     3  import (
     4  	"errors"
     5  	"sync"
     6  
     7  	"github.com/unicornultrafoundation/go-helios/hash"
     8  	"github.com/unicornultrafoundation/go-helios/native/idx"
     9  	"github.com/unicornultrafoundation/go-helios/native/pos"
    10  	"github.com/unicornultrafoundation/go-u2u/common"
    11  	"github.com/unicornultrafoundation/go-u2u/core/state"
    12  	"github.com/unicornultrafoundation/go-u2u/core/types"
    13  
    14  	"github.com/unicornultrafoundation/go-u2u/native"
    15  	"github.com/unicornultrafoundation/go-u2u/u2u"
    16  	"github.com/unicornultrafoundation/go-u2u/valkeystore"
    17  	"github.com/unicornultrafoundation/go-u2u/vecmt"
    18  )
    19  
    20  var (
    21  	ErrNotEnoughGasPower = errors.New("not enough gas power")
    22  )
    23  
    24  type (
    25  	// External world
    26  	External interface {
    27  		sync.Locker
    28  		Reader
    29  
    30  		Check(e *native.EventPayload, parents native.Events) error
    31  		Process(*native.EventPayload) error
    32  		Broadcast(*native.EventPayload)
    33  		Build(*native.MutableEventPayload, func()) error
    34  		DagIndex() *vecmt.Index
    35  
    36  		IsBusy() bool
    37  		IsSynced() bool
    38  		PeersNum() int
    39  
    40  		StateDB() *state.StateDB
    41  	}
    42  
    43  	// aliases for mock generator
    44  	Signer   valkeystore.SignerI
    45  	TxSigner types.Signer
    46  
    47  	// World is an emitter's environment
    48  	World struct {
    49  		External
    50  		TxPool   TxPool
    51  		Signer   valkeystore.SignerI
    52  		TxSigner types.Signer
    53  	}
    54  )
    55  
    56  type LlrReader interface {
    57  	GetLowestBlockToDecide() idx.Block
    58  	GetLastBV(id idx.ValidatorID) *idx.Block
    59  	GetBlockRecordHash(idx.Block) *hash.Hash
    60  	GetBlockEpoch(idx.Block) idx.Epoch
    61  
    62  	GetLowestEpochToDecide() idx.Epoch
    63  	GetLastEV(id idx.ValidatorID) *idx.Epoch
    64  	GetEpochRecordHash(epoch idx.Epoch) *hash.Hash
    65  }
    66  
    67  // Reader is a callback for getting events from an external storage.
    68  type Reader interface {
    69  	LlrReader
    70  	GetLatestBlockIndex() idx.Block
    71  	GetEpochValidators() (*pos.Validators, idx.Epoch)
    72  	GetEvent(hash.Event) *native.Event
    73  	GetEventPayload(hash.Event) *native.EventPayload
    74  	GetLastEvent(epoch idx.Epoch, from idx.ValidatorID) *hash.Event
    75  	GetHeads(idx.Epoch) hash.Events
    76  	GetGenesisTime() native.Timestamp
    77  	GetRules() u2u.Rules
    78  }
    79  
    80  type TxPool interface {
    81  	// Has returns an indicator whether txpool has a transaction cached with the
    82  	// given hash.
    83  	Has(hash common.Hash) bool
    84  	// Pending should return pending transactions.
    85  	// The slice should be modifiable by the caller.
    86  	Pending(enforceTips bool) (map[common.Address]types.Transactions, error)
    87  
    88  	// Count returns the total number of transactions
    89  	Count() int
    90  }