kernel

package
v0.18.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2024 License: GPL-3.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FinalPoolSlotsLimit     = config.SnapshotSyncRoundThreshold * 8
	FinalPoolRoundSizeLimit = 1024
	CachePoolSnapshotsLimit = 256
)
View Source
const (
	CosiActionSelfEmpty = iota
	CosiActionSelfCommitment
	CosiActionSelfResponse
	CosiActionExternalAnnouncement
	CosiActionExternalChallenge
	CosiActionFinalization
	CosiActionExternalCommitments
	CosiActionSelfFullCommitment
	CosiActionExternalFullChallenge
)
View Source
const (
	MintYearDays              = 365
	KernelNetworkLegacyEnding = 1706
	OneDay                    = 24 * uint64(time.Hour)
)
View Source
const (
	// All nodes should ensure consistent snapshots to keep the round space small.
	SlashReasonRoundSpace = 0x1

	// After a kernel node is pledged successfully, it must be accepted timely.
	SlashReasonLateAccept = 0x2

	// The payee should spend the node removal output as soon as possible.
	// The slash could be done by kernel nodes directly when the consumption
	// of the output happens.
	SlashReasonLateRemove = 0x3

	// A sequencer node must produce consistent topology with witness signature.
	// Light node could provide evidence of inconsistent topology.
	SlashReasonInconsistentWitness = 0x4

	// A node produces snapshot x in round A, then announces round B, which
	// references round A with only snapshot x in it. However during round A,
	// the node also announces snapshot y and gathered enough signatures, but
	// this snapshot y is never delivered to other nodes after the finalization
	// then the round A is considered stale if anyone could provide evidence of
	// the existence of the finalized snapshot y. Light node could do this job.
	//
	// Another kind of stale snapshot could directly happen in round A without
	// the announcement of round B. The node just announces x and keeps y, then
	// stops all future works. This can already be punished by large space and
	// mint rewards, but we still need to add more measurements for this behavior.
	// Because this stale snapshot y must be excluded from mint works
	// calculation forever, but if this node contiues to work after a long time,
	// and the failure to identity this stale snapshot timely, could result in
	// the full node sync failure of a fresh boot node. So the best punishment
	// is to remove this node, together with the large round space check.
	SlashReasonStaleSnapshot = 0x5
)
View Source
const MaxKernelNodesCount = 50

Variables

View Source
var (
	MintPool        = common.NewInteger(500000)
	MintLiquidity   = common.NewInteger(500000)
	MintYearPercent = common.NewInteger(10).Ration(common.NewInteger(100))
)

Functions

func TestMockDiff added in v0.6.2

func TestMockDiff(at time.Duration)

func TestMockReset added in v0.8.3

func TestMockReset()

Types

type ActionBuffer added in v0.12.11

type ActionBuffer chan *CosiAction

func (ActionBuffer) Offer added in v0.12.11

func (ab ActionBuffer) Offer(m *CosiAction) error

func (ActionBuffer) Poll added in v0.12.11

func (ab ActionBuffer) Poll() *CosiAction

type CNode added in v0.9.0

type CNode struct {
	IdForNetwork   crypto.Hash
	Signer         common.Address
	Payee          common.Address
	Transaction    crypto.Hash
	Timestamp      uint64
	State          string
	ConsensusIndex int
}

type CNodeWork added in v0.11.0

type CNodeWork struct {
	CNode
	Work common.Integer
}

type CacheRound

type CacheRound struct {
	NodeId     crypto.Hash
	Number     uint64
	Timestamp  uint64
	References *common.RoundLink
	Snapshots  []*common.Snapshot
	// contains filtered or unexported fields
}

func (*CacheRound) Copy

func (c *CacheRound) Copy() *CacheRound

func (*CacheRound) Gap

func (c *CacheRound) Gap() (uint64, uint64)

func (*CacheRound) ValidateSnapshot

func (c *CacheRound) ValidateSnapshot(s *common.Snapshot) error

type Chain added in v0.9.0

type Chain struct {
	sync.RWMutex

	ChainId       crypto.Hash
	ConsensusInfo *CNode

	State *ChainState

	CosiRandoms        map[crypto.Key]*crypto.Key
	UsedRandoms        map[crypto.Hash]*crypto.Key
	CosiCommitments    map[crypto.Hash][]*crypto.Key
	UsedCommitments    map[crypto.Key]bool
	ComitmentsSentTime time.Time

	CosiAggregators map[crypto.Hash]*CosiAggregator
	CosiVerifiers   map[crypto.Hash]*CosiVerifier
	CachePool       ActionBuffer
	FinalPool       [FinalPoolSlotsLimit]*ChainRound
	FinalIndex      int
	FinalCount      int
	// contains filtered or unexported fields
}

func (*Chain) AddSnapshot added in v0.9.1

func (chain *Chain) AddSnapshot(final *FinalRound, cache *CacheRound, s *common.Snapshot, signers []crypto.Hash) error

func (*Chain) AggregateMintWork added in v0.11.0

func (chain *Chain) AggregateMintWork()

func (*Chain) AggregateRoundSpace added in v0.14.0

func (chain *Chain) AggregateRoundSpace()

func (*Chain) AppendCosiAction added in v0.9.0

func (chain *Chain) AppendCosiAction(m *CosiAction) error

func (*Chain) AppendFinalSnapshot added in v0.9.0

func (chain *Chain) AppendFinalSnapshot(peerId crypto.Hash, s *common.Snapshot) error

func (*Chain) AppendSelfEmpty added in v0.9.0

func (chain *Chain) AppendSelfEmpty(s *common.Snapshot) error

func (*Chain) ConsensusKeys added in v0.9.1

func (chain *Chain) ConsensusKeys(round, timestamp uint64) ([]crypto.Hash, []*crypto.Key)

func (*Chain) ConsumeFinalActions added in v0.9.0

func (chain *Chain) ConsumeFinalActions()

func (*Chain) IsPledging added in v0.9.1

func (chain *Chain) IsPledging() bool

func (*Chain) QueuePollSnapshots added in v0.9.0

func (chain *Chain) QueuePollSnapshots()

func (*Chain) StateCopy added in v0.9.1

func (chain *Chain) StateCopy() (*CacheRound, *FinalRound)

func (*Chain) StepForward added in v0.9.0

func (chain *Chain) StepForward()

func (*Chain) Teardown added in v0.9.0

func (chain *Chain) Teardown()

type ChainRound added in v0.9.0

type ChainRound struct {
	Number    uint64
	Size      int
	Timestamp uint64
	Snapshots [FinalPoolRoundSizeLimit]*PeerSnapshot
	// contains filtered or unexported fields
}

type ChainState added in v0.9.0

type ChainState struct {
	CacheRound   *CacheRound
	FinalRound   *FinalRound
	RoundHistory []*FinalRound
	RoundLinks   map[crypto.Hash]uint64
}

type CosiAction added in v0.5.0

type CosiAction struct {
	Action       int
	PeerId       crypto.Hash
	SnapshotHash crypto.Hash
	Snapshot     *common.Snapshot
	Commitment   *crypto.Key
	Signature    *crypto.CosiSignature
	Response     *[32]byte
	Transaction  *common.VersionedTransaction
	WantTx       bool
	Commitments  []*crypto.Key
	Challenge    *crypto.Key
	// contains filtered or unexported fields
}

type CosiAggregator added in v0.5.0

type CosiAggregator struct {
	Snapshot       *common.Snapshot
	Transaction    *common.VersionedTransaction
	WantTxs        map[crypto.Hash]bool
	FullChallenges map[crypto.Hash]bool
	Commitments    map[int]*crypto.Key
	Responses      map[int]*[32]byte
}

type CosiChainData added in v0.9.1

type CosiChainData struct {
	PN *CNode
	CN *CNode
	TX *common.VersionedTransaction
	F  bool
}

type CosiVerifier added in v0.5.0

type CosiVerifier struct {
	Snapshot   *common.Snapshot
	Commitment *crypto.Key
	// contains filtered or unexported fields
}

type FinalRound

type FinalRound struct {
	NodeId crypto.Hash
	Number uint64
	Start  uint64
	End    uint64
	Hash   crypto.Hash
}

func (*FinalRound) Common added in v0.9.4

func (f *FinalRound) Common() *common.Round

func (*FinalRound) Copy

func (f *FinalRound) Copy() *FinalRound

type Node

type Node struct {
	IdForNetwork crypto.Hash
	Signer       common.Address

	Peer          *p2p.Peer
	TopoCounter   *TopologicalSequence
	SyncPoints    *syncMap
	SyncPointsMap map[crypto.Hash]*p2p.SyncPoint

	GraphTimestamp uint64
	Epoch          uint64
	LastMint       uint64
	// contains filtered or unexported fields
}

func SetupNode

func SetupNode(custom *config.Custom, store storage.Store, cache *ristretto.Cache, gns *common.Genesis) (*Node, error)

func (*Node) Authenticate

func (node *Node) Authenticate(msg []byte) (crypto.Hash, string, error)

func (*Node) AuthenticateAs added in v0.18.0

func (node *Node) AuthenticateAs(recipientId crypto.Hash, msg []byte, timeoutSec int64) (*p2p.AuthToken, error)

func (*Node) BootChain added in v0.14.3

func (node *Node) BootChain(id crypto.Hash) *Chain

func (*Node) BuildAuthenticationMessage

func (node *Node) BuildAuthenticationMessage(relayerId crypto.Hash) []byte

func (*Node) BuildGraph

func (node *Node) BuildGraph() []*p2p.SyncPoint

func (*Node) CachePutTransaction

func (node *Node) CachePutTransaction(peerId crypto.Hash, tx *common.VersionedTransaction) error

func (*Node) CheckBroadcastedToPeers added in v0.2.12

func (node *Node) CheckBroadcastedToPeers() bool

func (*Node) CheckCatchUpWithPeers added in v0.2.12

func (node *Node) CheckCatchUpWithPeers() bool

func (*Node) ConsensusReady added in v0.9.1

func (node *Node) ConsensusReady(cn *CNode, timestamp uint64) bool

An accepted node can sign transactions only when it satisfies either: 1. It is a genesis node. 2. It has been accepted more than 12 hours.

func (*Node) ConsensusThreshold added in v0.5.0

func (node *Node) ConsensusThreshold(timestamp uint64, final bool) int

func (*Node) CosiAggregateSelfCommitments added in v0.5.0

func (node *Node) CosiAggregateSelfCommitments(peerId crypto.Hash, snap crypto.Hash, commitment *crypto.Key, wantTx bool, data []byte, sig *crypto.Signature) error

func (*Node) CosiAggregateSelfResponses added in v0.5.0

func (node *Node) CosiAggregateSelfResponses(peerId crypto.Hash, snap crypto.Hash, response *[32]byte) error

func (*Node) CosiQueueExternalAnnouncement added in v0.5.0

func (node *Node) CosiQueueExternalAnnouncement(peerId crypto.Hash, s *common.Snapshot, commitment *crypto.Key, sig *crypto.Signature) error

func (*Node) CosiQueueExternalChallenge added in v0.5.0

func (node *Node) CosiQueueExternalChallenge(peerId crypto.Hash, snap crypto.Hash, cosi *crypto.CosiSignature, ver *common.VersionedTransaction) error

func (*Node) CosiQueueExternalCommitments added in v0.14.6

func (node *Node) CosiQueueExternalCommitments(peerId crypto.Hash, commitments []*crypto.Key, data []byte, sig *crypto.Signature) error

func (*Node) CosiQueueExternalFullChallenge added in v0.14.6

func (node *Node) CosiQueueExternalFullChallenge(peerId crypto.Hash, s *common.Snapshot, commitment, challenge *crypto.Key, cosi *crypto.CosiSignature, ver *common.VersionedTransaction) error

func (*Node) ElectionLoop added in v0.3.5

func (node *Node) ElectionLoop()

func (*Node) GetAcceptedOrPledgingNode added in v0.9.1

func (node *Node) GetAcceptedOrPledgingNode(id crypto.Hash) *CNode

func (*Node) GetCacheStore added in v0.2.18

func (node *Node) GetCacheStore() *ristretto.Cache

func (*Node) GetRemovedOrCancelledNode added in v0.14.0

func (node *Node) GetRemovedOrCancelledNode(id crypto.Hash, timestamp uint64) *CNode

func (*Node) GetRemovingOrSlashingNode added in v0.14.4

func (node *Node) GetRemovingOrSlashingNode(id crypto.Hash) *CNode

this returns the first to be removed node as normal, then if some node is being slashed, this will return it instead of the normal one, thus causes the removing or slashing node changes.

a removing or slashing node is not able to produce works during the state, but whenever another slashing node with more priority proceeds it, it resumes working again, a large round space may happen.

to make it equal and fair, the large round space slashing will cause zero loss, and the payee will get back the whole pledge. so the punishment to a removing or slashing node is only drastically mint decline.

func (*Node) ListMintWorks added in v0.11.1

func (node *Node) ListMintWorks(batch uint64) (map[crypto.Hash][2]uint64, error)

func (*Node) ListRoundSpaces added in v0.16.5

func (node *Node) ListRoundSpaces(cids []crypto.Hash, day uint64) (map[crypto.Hash][]*common.RoundSpace, error)

func (*Node) LoadAllChainsAndGraphTimestamp added in v0.14.3

func (node *Node) LoadAllChainsAndGraphTimestamp(store storage.Store, networkId crypto.Hash) error

func (*Node) LoadConsensusNodes

func (node *Node) LoadConsensusNodes() error

func (*Node) LoadGenesis

func (node *Node) LoadGenesis(gns *common.Genesis) error

func (*Node) LoadRoundGraph added in v0.13.2

func (node *Node) LoadRoundGraph() (map[crypto.Hash]*CacheRound, map[crypto.Hash]*FinalRound)

func (*Node) Loop added in v0.1.2

func (node *Node) Loop() error

func (*Node) MintLoop added in v0.1.1

func (node *Node) MintLoop()

func (*Node) NetworkId

func (node *Node) NetworkId() crypto.Hash

func (*Node) NewTransaction added in v0.14.0

func (node *Node) NewTransaction(assetId crypto.Hash) *common.Transaction

this is needed to handle mainnet transaction version upgrading fork

func (*Node) NodesListWithoutState added in v0.9.1

func (node *Node) NodesListWithoutState(threshold uint64, acceptedOnly bool) []*CNode

func (*Node) PledgingNode added in v0.9.1

func (node *Node) PledgingNode(timestamp uint64) *CNode

func (*Node) PoolSize added in v0.6.0

func (node *Node) PoolSize() (common.Integer, error)

func (*Node) QueueState added in v0.12.7

func (node *Node) QueueState() (uint64, uint64, map[string][2]uint64)

func (*Node) QueueTransaction added in v0.1.2

func (node *Node) QueueTransaction(tx *common.VersionedTransaction) (string, error)

func (*Node) ReadAllNodesWithoutState added in v0.9.1

func (node *Node) ReadAllNodesWithoutState() []crypto.Hash

func (*Node) ReadSnapshotsForNodeRound

func (node *Node) ReadSnapshotsForNodeRound(nodeIdWithNetwork crypto.Hash, round uint64) ([]*common.SnapshotWithTopologicalOrder, error)

func (*Node) ReadSnapshotsSinceTopology

func (node *Node) ReadSnapshotsSinceTopology(offset, count uint64) ([]*common.SnapshotWithTopologicalOrder, error)

func (*Node) SPS added in v0.9.0

func (node *Node) SPS() float64

func (*Node) SendTransactionToPeer

func (node *Node) SendTransactionToPeer(peerId, hash crypto.Hash) error

func (*Node) SignData added in v0.18.0

func (node *Node) SignData(data []byte) crypto.Signature

func (*Node) SnapshotVersion added in v0.14.0

func (node *Node) SnapshotVersion() uint8

func (*Node) TPS added in v0.13.5

func (node *Node) TPS() float64

func (*Node) Teardown added in v0.8.3

func (node *Node) Teardown()

func (*Node) TopoWrite added in v0.9.0

func (node *Node) TopoWrite(s *common.Snapshot, signers []crypto.Hash) *common.SnapshotWithTopologicalOrder

func (*Node) TopologicalOrder added in v0.1.2

func (node *Node) TopologicalOrder() uint64

func (*Node) UpdateSyncPoint

func (node *Node) UpdateSyncPoint(peerId crypto.Hash, points []*p2p.SyncPoint, data []byte, sig *crypto.Signature) error

func (*Node) Uptime added in v0.1.14

func (node *Node) Uptime() time.Duration

func (*Node) VerifyAndQueueAppendSnapshotFinalization added in v0.5.0

func (node *Node) VerifyAndQueueAppendSnapshotFinalization(peerId crypto.Hash, s *common.Snapshot) error

func (*Node) WitnessSnapshot added in v0.9.7

func (node *Node) WitnessSnapshot(s *common.SnapshotWithTopologicalOrder) *SnapshotWitness

type NodeStateSequence added in v0.12.10

type NodeStateSequence struct {
	Timestamp         uint64
	NodesWithoutState []*CNode
}

type PeerSnapshot added in v0.9.0

type PeerSnapshot struct {
	Snapshot *common.Snapshot
	// contains filtered or unexported fields
}

type SnapshotWitness added in v0.9.7

type SnapshotWitness struct {
	Signature *crypto.Signature
	Timestamp uint64
}

type TopologicalSequence

type TopologicalSequence struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*TopologicalSequence) TopoStats added in v0.9.0

func (topo *TopologicalSequence) TopoStats(node *Node)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL