-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.go
117 lines (96 loc) · 3.71 KB
/
api.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
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package simplex
import (
"context"
"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.
BuildBlock(ctx context.Context, metadata ProtocolMetadata) (Block, bool)
// IncomingBlock returns when either the given context is cancelled,
// or when the application signals that a block should be built.
IncomingBlock(ctx context.Context)
}
type Storage interface {
Height() uint64
Retrieve(seq uint64) (Block, FinalizationCertificate, bool)
Index(block Block, certificate FinalizationCertificate)
}
type Communication interface {
// ListNodes returns all nodes known to the application.
ListNodes() []NodeID
// SendMessage sends a message to the given destination node
SendMessage(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)
}
type Block interface {
// BlockHeader encodes a succinct and collision-free representation of a block.
BlockHeader() BlockHeader
// Bytes returns a byte encoding of the block
Bytes() []byte
// Verify verifies the block by speculatively executing it on top of its ancestor.
Verify() error
}
// BlockDeserializer deserializes blocks according to formatting
// enforced by the application.
type BlockDeserializer interface {
// DeserializeBlock parses the given bytes and initializes a Block.
// Returns an error upon failure.
DeserializeBlock(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)
}