-
Notifications
You must be signed in to change notification settings - Fork 210
/
interface.go
153 lines (125 loc) · 4.33 KB
/
interface.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package activation
import (
"context"
"fmt"
"io"
"time"
"github.com/spacemeshos/post/shared"
"github.com/spacemeshos/post/verifying"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/sql/localsql/nipost"
)
//go:generate mockgen -typed -package=activation -destination=./mocks.go -source=./interface.go
type AtxReceiver interface {
OnAtx(*types.ActivationTxHeader)
}
type PostVerifier interface {
io.Closer
Verify(ctx context.Context, p *shared.Proof, m *shared.ProofMetadata, opts ...verifying.OptionFunc) error
}
type scaler interface {
scale(int)
}
// validatorOption is a functional option type for the validator.
type validatorOption func(*validatorOptions)
type nipostValidator interface {
InitialNIPostChallenge(challenge *types.NIPostChallenge, atxs atxProvider, goldenATXID types.ATXID) error
NIPostChallenge(challenge *types.NIPostChallenge, atxs atxProvider, nodeID types.NodeID) error
NIPost(
ctx context.Context,
nodeId types.NodeID,
commitmentAtxId types.ATXID,
NIPost *types.NIPost,
expectedChallenge types.Hash32,
numUnits uint32,
opts ...validatorOption,
) (uint64, error)
NumUnits(cfg *PostConfig, numUnits uint32) error
IsVerifyingFullPost() bool
Post(
ctx context.Context,
nodeId types.NodeID,
commitmentAtxId types.ATXID,
Post *types.Post,
PostMetadata *types.PostMetadata,
numUnits uint32,
opts ...validatorOption,
) error
PostMetadata(cfg *PostConfig, metadata *types.PostMetadata) error
VRFNonce(
nodeId types.NodeID,
commitmentAtxId types.ATXID,
vrfNonce *types.VRFPostIndex,
PostMetadata *types.PostMetadata,
numUnits uint32,
) error
PositioningAtx(id types.ATXID, atxs atxProvider, goldenATXID types.ATXID, pubepoch types.EpochID) error
// VerifyChain fully verifies all dependencies of the given ATX and the ATX itself.
VerifyChain(ctx context.Context, id, goldenATXID types.ATXID, opts ...VerifyChainOption) error
}
type layerClock interface {
AwaitLayer(layerID types.LayerID) <-chan struct{}
CurrentLayer() types.LayerID
LayerToTime(types.LayerID) time.Time
}
type nipostBuilder interface {
BuildNIPost(ctx context.Context, challenge *types.NIPostChallenge) (*nipost.NIPostState, error)
Proof(ctx context.Context, challenge []byte) (*types.Post, *types.PostInfo, error)
ResetState() error
}
type syncer interface {
RegisterForATXSynced() <-chan struct{}
}
type atxProvider interface {
GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)
}
// PostSetupProvider defines the functionality required for Post setup.
// This interface is used by the atx builder and currently implemented by the PostSetupManager.
// Eventually most of the functionality will be moved to the PoSTClient.
type postSetupProvider interface {
PrepareInitializer(ctx context.Context, opts PostSetupOpts) error
StartSession(context context.Context) error
Status() *PostSetupStatus
Reset() error
}
// SmeshingProvider defines the functionality required for the node's Smesher API.
type SmeshingProvider interface {
Smeshing() bool
StartSmeshing(types.Address) error
StopSmeshing(bool) error
SmesherID() types.NodeID
Coinbase() types.Address
SetCoinbase(coinbase types.Address)
}
// poetClient servers as an interface to communicate with a PoET server.
// It is used to submit challenges and fetch proofs.
type poetClient interface {
Address() string
PowParams(ctx context.Context) (*PoetPowParams, error)
// Submit registers a challenge in the proving service current open round.
Submit(
ctx context.Context,
deadline time.Time,
prefix, challenge []byte,
signature types.EdSignature,
nodeID types.NodeID,
pow PoetPoW,
) (*types.PoetRound, error)
// Proof returns the proof for the given round ID.
Proof(ctx context.Context, roundID string) (*types.PoetProofMessage, []types.Member, error)
}
type poetDbAPI interface {
GetProof(types.PoetProofRef) (*types.PoetProof, *types.Hash32, error)
ValidateAndStore(ctx context.Context, proofMessage *types.PoetProofMessage) error
}
var (
ErrPostClientClosed = fmt.Errorf("post client closed")
ErrPostClientNotConnected = fmt.Errorf("post service not registered")
)
type postService interface {
Client(nodeId types.NodeID) (PostClient, error)
}
type PostClient interface {
Info(ctx context.Context) (*types.PostInfo, error)
Proof(ctx context.Context, challenge []byte) (*types.Post, *types.PostInfo, error)
}