/
interfaces.go
85 lines (71 loc) · 2.82 KB
/
interfaces.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
80
81
82
83
84
85
// Copyright 2021 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package sync
import (
"encoding/json"
"sync"
"github.com/ChainSafe/gossamer/dot/peerset"
"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/libp2p/go-libp2p/core/peer"
)
// BlockState is the interface for the block state
type BlockState interface {
BestBlockHeader() (*types.Header, error)
BestBlockNumber() (number uint, err error)
CompareAndSetBlockData(bd *types.BlockData) error
GetBlockBody(common.Hash) (*types.Body, error)
GetHeader(common.Hash) (*types.Header, error)
HasHeader(hash common.Hash) (bool, error)
Range(startHash, endHash common.Hash) (hashes []common.Hash, err error)
RangeInMemory(start, end common.Hash) ([]common.Hash, error)
GetReceipt(common.Hash) ([]byte, error)
GetMessageQueue(common.Hash) ([]byte, error)
GetJustification(common.Hash) ([]byte, error)
SetJustification(hash common.Hash, data []byte) error
GetHashByNumber(blockNumber uint) (common.Hash, error)
GetBlockByHash(common.Hash) (*types.Block, error)
GetRuntime(blockHash common.Hash) (runtime runtime.Instance, err error)
StoreRuntime(blockHash common.Hash, runtime runtime.Instance)
GetHighestFinalisedHeader() (*types.Header, error)
GetFinalisedNotifierChannel() chan *types.FinalisationInfo
GetHeaderByNumber(num uint) (*types.Header, error)
GetAllBlocksAtNumber(num uint) ([]common.Hash, error)
IsDescendantOf(parent, child common.Hash) (bool, error)
}
// StorageState is the interface for the storage state
type StorageState interface {
TrieState(root *common.Hash) (*rtstorage.TrieState, error)
sync.Locker
}
// TransactionState is the interface for transaction queue methods
type TransactionState interface {
RemoveExtrinsic(ext types.Extrinsic)
}
// BabeVerifier deals with BABE block verification
type BabeVerifier interface {
VerifyBlock(header *types.Header) error
}
// FinalityGadget implements justification verification functionality
type FinalityGadget interface {
VerifyBlockJustification(common.Hash, []byte) error
}
// BlockImportHandler is the interface for the handler of newly imported blocks
type BlockImportHandler interface {
HandleBlockImport(block *types.Block, state *rtstorage.TrieState, announce bool) error
}
// Network is the interface for the network
type Network interface {
// Peers returns a list of currently connected peers
Peers() []common.PeerInfo
// ReportPeer reports peer based on the peer behaviour.
ReportPeer(change peerset.ReputationChange, p peer.ID)
AllConnectedPeersIDs() []peer.ID
BlockAnnounceHandshake(*types.Header) error
}
// Telemetry is the telemetry client to send telemetry messages.
type Telemetry interface {
SendMessage(msg json.Marshaler)
}