/
state.go
79 lines (67 loc) · 2.7 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package babe
import (
"sync"
"time"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/runtime"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/transaction"
)
type SlotState interface {
CheckEquivocation(slotNow, slot uint64, header *types.Header,
signer types.AuthorityID) (*types.BabeEquivocationProof, error)
}
// BlockState interface for block state methods
type BlockState interface {
BestBlockHash() common.Hash
BestBlockHeader() (*types.Header, error)
AddBlock(*types.Block) error
GetAllBlocksAtDepth(hash common.Hash) []common.Hash
GetHeader(common.Hash) (*types.Header, error)
GetBlockByNumber(blockNumber uint) (*types.Block, error)
GetBlockHashesBySlot(slot uint64) (blockHashes []common.Hash, err error)
GenesisHash() common.Hash
GetSlotForBlock(common.Hash) (uint64, error)
IsDescendantOf(parent, child common.Hash) (bool, error)
NumberIsFinalised(blockNumber uint) (bool, error)
GetRuntime(blockHash common.Hash) (runtime runtime.Instance, err error)
StoreRuntime(common.Hash, runtime.Instance)
ImportedBlockNotifierManager
}
// ImportedBlockNotifierManager is the interface for block notification channels
type ImportedBlockNotifierManager interface {
GetImportedBlockNotifierChannel() chan *types.Block
FreeImportedBlockNotifierChannel(ch chan *types.Block)
}
// StorageState interface for storage state methods
type StorageState interface {
TrieState(hash *common.Hash) (*rtstorage.TrieState, error)
sync.Locker
}
// TransactionState is the interface for transaction queue methods
type TransactionState interface {
Push(vt *transaction.ValidTransaction) (common.Hash, error)
PopWithTimer(timerCh <-chan time.Time) (tx *transaction.ValidTransaction)
}
// EpochState is the interface for epoch methods
type EpochState interface {
GetEpochLength() (uint64, error)
GetSlotDuration() (time.Duration, error)
SetCurrentEpoch(epoch uint64) error
GetCurrentEpoch() (uint64, error)
GetEpochDataRaw(epoch uint64, header *types.Header) (*types.EpochDataRaw, error)
GetConfigData(epoch uint64, header *types.Header) (*types.ConfigData, error)
GetLatestConfigData() (*types.ConfigData, error)
GetStartSlotForEpoch(epoch uint64) (uint64, error)
GetEpochForBlock(header *types.Header) (uint64, error)
SetFirstSlot(slot uint64) error
GetLatestEpochDataRaw() (*types.EpochDataRaw, error)
SkipVerify(*types.Header) (bool, error)
}
// BlockImportHandler is the interface for the handler of new blocks
type BlockImportHandler interface {
HandleBlockProduced(block *types.Block, state *rtstorage.TrieState) error
}