-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.go
More file actions
137 lines (112 loc) · 4.51 KB
/
api.go
File metadata and controls
137 lines (112 loc) · 4.51 KB
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
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package simplex
import (
"context"
"fmt"
"go.uber.org/zap"
)
type Logger interface {
// Log that a fatal error has occurred. The program should likely exit soon
// after this is called
Fatal(msg string, fields ...zap.Field)
// Log that an error has occurred. The program should be able to recover
// from this error
Error(msg string, fields ...zap.Field)
// Log that an event has occurred that may indicate a future error or
// vulnerability
Warn(msg string, fields ...zap.Field)
// Log an event that may be useful for a user to see to measure the progress
// of the protocol
Info(msg string, fields ...zap.Field)
// Log an event that may be useful for understanding the order of the
// execution of the protocol
Trace(msg string, fields ...zap.Field)
// Log an event that may be useful for a programmer to see when debuging the
// execution of the protocol
Debug(msg string, fields ...zap.Field)
// Log extremely detailed events that can be useful for inspecting every
// aspect of the program
Verbo(msg string, fields ...zap.Field)
}
type BlockBuilder interface {
// BuildBlock blocks until some transactions are available to be batched into a block,
// in which case a block and true are returned.
// When the given context is cancelled by the caller, returns false.
// The given metadata and blacklist are encoded into the built block.
BuildBlock(ctx context.Context, metadata ProtocolMetadata, blacklist Blacklist) (VerifiedBlock, bool)
// WaitForPendingBlock returns when either the given context is cancelled,
// or when the application signals that a block should be built.
WaitForPendingBlock(ctx context.Context)
}
var ErrBlockNotFound = fmt.Errorf("block not found")
type Storage interface {
NumBlocks() uint64
// Retrieve returns the block and finalization at [seq].
// If [seq] the block cannot be found, returns ErrBlockNotFound.
Retrieve(seq uint64) (VerifiedBlock, Finalization, error)
Index(ctx context.Context, block VerifiedBlock, certificate Finalization) error
}
type Communication interface {
// Nodes returns all nodes that participate in the epoch.
Nodes() []NodeID
// Send sends a message to the given destination node
Send(msg *Message, destination NodeID)
// Broadcast broadcasts the given message to all nodes.
// Does not send it to yourself.
Broadcast(msg *Message)
}
type Signer interface {
Sign(message []byte) ([]byte, error)
}
type SignatureVerifier interface {
Verify(message []byte, signature []byte, signer NodeID) error
}
type WriteAheadLog interface {
Append([]byte) error
ReadAll() ([][]byte, error)
Close() error
}
type Block interface {
// BlockHeader encodes a succinct and collision-free representation of a block.
BlockHeader() BlockHeader
Blacklist() Blacklist
// Verify verifies the block by speculatively executing it on top of its ancestor.
Verify(ctx context.Context) (VerifiedBlock, error)
}
type VerifiedBlock interface {
// BlockHeader encodes a succinct and collision-free representation of a block.
BlockHeader() BlockHeader
Blacklist() Blacklist
// Bytes returns a byte encoding of the block
Bytes() ([]byte, error)
}
// BlockDeserializer deserializes blocks according to formatting
// enforced by the application.
type BlockDeserializer interface {
// DeserializeBlock parses the given bytes and initializes a VerifiedBlock.
// Returns an error upon failure.
DeserializeBlock(ctx context.Context, bytes []byte) (Block, error)
}
// Signature encodes a signature and the node that signed it, without the message it was signed on.
type Signature struct {
// Signer is the NodeID of the creator of the signature.
Signer NodeID
// Value is the byte representation of the signature.
Value []byte
}
// QCDeserializer deserializes QuorumCertificates according to formatting
type QCDeserializer interface {
// DeserializeQuorumCertificate parses the given bytes and initializes a QuorumCertificate.
// Returns an error upon failure.
DeserializeQuorumCertificate(bytes []byte) (QuorumCertificate, error)
}
// SignatureAggregator aggregates signatures into a QuorumCertificate
type SignatureAggregator interface {
// Aggregate aggregates several signatures into a QuorumCertificate
Aggregate([]Signature) (QuorumCertificate, error)
// IsQuorum returns true if the given signers constitute a quorum.
// In the case of PoA, this means at least a quorum of the nodes are given.
// In the case of PoS, this means at least two thirds of the st.
IsQuorum([]NodeID) bool
}