Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diamondhands Hyeprsync Review #1118

Open
wants to merge 65 commits into
base: feature/proof-of-stake
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
fefb100
Add BLS Keystore
tholonious Dec 15, 2023
a7edc6c
PoS Validator Constants and Network Changes (#876)
AeonSw4n Dec 28, 2023
b2b113c
PoS Validator Connect/Disconnect Flow (#768)
AeonSw4n Dec 29, 2023
43d8e36
PoS RemoteNode and RemoteNodeId (#857)
AeonSw4n Jan 6, 2024
2eb2632
PoS Remote Node Indexer and Manager (#879)
AeonSw4n Jan 10, 2024
a86d1c8
PoS HandshakeController (#860)
AeonSw4n Jan 11, 2024
48c0677
Add HandshakeController (#861)
AeonSw4n Jan 24, 2024
21ba1dd
Add validator deduplication test (#942)
AeonSw4n Jan 29, 2024
59af74d
Revert "Code split" (#943)
AeonSw4n Jan 29, 2024
3901564
Revert "Code split" (#944)
AeonSw4n Jan 29, 2024
4a53182
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Jan 29, 2024
c057262
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Jan 29, 2024
3543f2c
Nits
AeonSw4n Jan 29, 2024
927df23
PoS NetworkManager RemoteNode Cleanup (#945)
AeonSw4n Jan 30, 2024
f60ec17
PoS NetworkManager Address (#957)
AeonSw4n Jan 30, 2024
baa91ae
PoS NetworkManager Rename and Nits (#959)
AeonSw4n Jan 30, 2024
c7317f5
PoS NetworkManager Fix Integration Tests (#960)
AeonSw4n Jan 30, 2024
edaf174
Fix fmt (#973)
AeonSw4n Jan 30, 2024
76bf439
PoS Networking and Syncing Documentation (#974)
AeonSw4n Jan 31, 2024
a6b26b7
Rewording (#981)
AeonSw4n Jan 31, 2024
20f2eb4
Rename (#986)
AeonSw4n Jan 31, 2024
5ffc022
PoS NetworkManager Fix Deadlock and Test AddIps (#996)
AeonSw4n Feb 1, 2024
1b0bc01
PoS NetworkManager Comment Nit (#997)
AeonSw4n Feb 1, 2024
b4454e0
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
AeonSw4n Feb 7, 2024
c9571c8
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 14, 2024
f4059c6
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 14, 2024
362d634
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 14, 2024
aa0fb85
Add ProtocolVersion To Regtest Params (#1035)
tholonious Feb 15, 2024
2a1e9c7
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 15, 2024
f0c7b5d
Fix Constructor Name for NetworkManager
tholonious Feb 15, 2024
94c8130
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 15, 2024
bc95c03
Broadcast Votes, Timeouts, and Block Proposals To Validators (#1036)
tholonious Feb 16, 2024
99d0a46
Use RemoteNode To Fetch Missing PoS Blocks (#1045)
tholonious Feb 16, 2024
2b3f154
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 20, 2024
d2f2cdd
Update Active Validator Connections In PoS Consensus (#1054)
tholonious Feb 20, 2024
50db24d
Remove Rollbacks To bestHeaderChain When bestChain is Mutated (#1055)
tholonious Feb 21, 2024
e87c72b
PoW Miner Event Loop Cleanup (#1056)
tholonious Feb 21, 2024
4239b8e
Log Peer Validator Vote Messages (#1057)
tholonious Feb 22, 2024
3d3b816
Log Peer Validator Timeout Messages (#1058)
tholonious Feb 22, 2024
6b52173
Merge branch 'feature/proof-of-stake' into feature/pos-networking-and…
tholonious Feb 22, 2024
f10d6dc
Request Missing HighQC Block For Timeout Message (#1061)
tholonious Feb 22, 2024
5d1bb33
Remove Peer Disconnects in Server._handleBlock (#1062)
tholonious Feb 22, 2024
ac60b95
Change log level for consensus events
tholonious Feb 22, 2024
c1a4cbb
Update regtest block producer domain
tholonious Feb 22, 2024
19e8511
Prevent Commited Tip Reorgs in ProcessHeaderPoS (#1063)
tholonious Feb 22, 2024
cf47baa
Add Estimate fee rate to mempool interface (#1066)
lazynina Feb 26, 2024
7ab45bb
Add BLS Public Key PKID Pair Entry Snapshot to core state (#1068)
lazynina Feb 26, 2024
5a20c5c
Fix txindex for failing txns (#1069)
lazynina Feb 28, 2024
ae9e118
Introduce failing txn type so state syncer understand failing txns (#…
lazynina Feb 28, 2024
0eff225
Support uncommitted blocks in state syncer mempool flush (#1065)
lazynina Feb 28, 2024
bf84888
Fix Connect failing txn test (#1071)
lazynina Feb 28, 2024
a94d728
noop
AeonSw4n Feb 28, 2024
1f644e8
Add support for seed hex in block producer seed (#1072)
lazynina Feb 28, 2024
0c40ac8
Make GetCommittedTip public (#1073)
lazynina Feb 29, 2024
9445f77
Assorted small enhancements for node restart w/ pos (#1079)
lazynina Feb 29, 2024
4bb7d42
pos_blockchain updates (#1074)
AeonSw4n Mar 1, 2024
e1312f9
Fix txindex dependent transaction within uncommitted blocks (#1082)
lazynina Mar 1, 2024
ea2db8f
Add flag to control number of mempool txns to sync in state syncer ro…
lazynina Mar 1, 2024
8b473a9
PoS update snapshot epoch duration (#1075)
AeonSw4n Mar 2, 2024
fdc2ed9
PoS deprecate DisconnectBlocksToHeight (#1076)
AeonSw4n Mar 2, 2024
013fd48
PoS batch BlockNode update in snapshot (#1077)
AeonSw4n Mar 2, 2024
3076f5a
Merge branch 'feature/pos-networking-and-syncing' into feature/pos-hy…
AeonSw4n Mar 2, 2024
6320285
p/pos-hypersync-archival-mode
AeonSw4n Mar 5, 2024
464aeaf
PoS Hypersync Archival Mode
AeonSw4n Mar 6, 2024
5b9cc96
Fix nit test race condition
AeonSw4n Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bls/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ func (publicKey *PublicKey) FromString(publicKeyString string) (*PublicKey, erro
return publicKey, err
}

func (publicKey *PublicKey) ToAbbreviatedString() string {
str := publicKey.ToString()
if len(str) <= 8 {
return str
}
return str[:8] + "..." + str[len(str)-8:]
}

func (publicKey *PublicKey) MarshalJSON() ([]byte, error) {
// This is called automatically by the JSON library when converting a
// bls.PublicKey to JSON. This is useful when passing a bls.PublicKey
Expand Down Expand Up @@ -324,6 +332,14 @@ func (signature *Signature) FromString(signatureString string) (*Signature, erro
return signature, nil
}

func (signature *Signature) ToAbbreviatedString() string {
str := signature.ToString()
if len(str) <= 8 {
return str
}
return str[:8] + "..." + str[len(str)-8:]
}

func (signature *Signature) MarshalJSON() ([]byte, error) {
// This is called automatically by the JSON library when converting a
// bls.Signature to JSON. This is useful when passing a bls.Signature
Expand Down
8 changes: 8 additions & 0 deletions bls/signature_no_relic.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (publicKey *PublicKey) FromString(publicKeyString string) (*PublicKey, erro
panic(BLSNoRelicError)
}

func (publicKey *PublicKey) ToAbbreviatedString() string {
panic(BLSNoRelicError)
}

func (publicKey *PublicKey) MarshalJSON() ([]byte, error) {
panic(BLSNoRelicError)
}
Expand Down Expand Up @@ -136,6 +140,10 @@ func (signature *Signature) FromString(signatureString string) (*Signature, erro
panic(BLSNoRelicError)
}

func (signature *Signature) ToAbbreviatedString() string {
panic(BLSNoRelicError)
}

func (signature *Signature) MarshalJSON() ([]byte, error) {
panic(BLSNoRelicError)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ type Config struct {
TimeEvents bool

// State Syncer
StateChangeDir string
StateChangeDir string
StateSyncerMempoolTxnSyncLimit uint64
}

func LoadConfig() *Config {
Expand Down Expand Up @@ -176,6 +177,7 @@ func LoadConfig() *Config {

// State Syncer
config.StateChangeDir = viper.GetString("state-change-dir")
config.StateSyncerMempoolTxnSyncLimit = viper.GetUint64("state-syncer-mempool-txn-sync-limit")

return &config
}
Expand Down
19 changes: 10 additions & 9 deletions cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
)

type Node struct {
Server *lib.Server
ChainDB *badger.DB
TXIndex *lib.TXIndex
Params *lib.DeSoParams
Config *Config
Postgres *lib.Postgres
Server *lib.Server
ChainDB *badger.DB
TXIndex *lib.TXIndex
Params *lib.DeSoParams
Config *Config
Postgres *lib.Postgres
Listeners []net.Listener

// IsRunning is false when a NewNode is created, set to true on Start(), set to false
// after Stop() is called. Mainly used in testing.
Expand Down Expand Up @@ -117,8 +118,7 @@ func (node *Node) Start(exitChannels ...*chan struct{}) {

// This just gets localhost listening addresses on the protocol port.
// Such as [{127.0.0.1 18000 } {::1 18000 }], and associated listener structs.
listeningAddrs, listeners := GetAddrsToListenOn(node.Config.ProtocolPort)
_ = listeningAddrs
_, node.Listeners = GetAddrsToListenOn(node.Config.ProtocolPort)

// If --connect-ips is not passed, we will connect the addresses from
// --add-ips, DNSSeeds, and DNSSeedGenerators.
Expand Down Expand Up @@ -238,7 +238,7 @@ func (node *Node) Start(exitChannels ...*chan struct{}) {
shouldRestart := false
node.Server, err, shouldRestart = lib.NewServer(
node.Params,
listeners,
node.Listeners,
desoAddrMgr,
node.Config.ConnectIPs,
node.ChainDB,
Expand Down Expand Up @@ -282,6 +282,7 @@ func (node *Node) Start(exitChannels ...*chan struct{}) {
node.Config.AugmentedBlockViewRefreshIntervalMillis,
node.Config.PosBlockProductionIntervalMilliseconds,
node.Config.PosTimeoutBaseDurationMilliseconds,
node.Config.StateSyncerMempoolTxnSyncLimit,
)
if err != nil {
// shouldRestart can be true if, on the previous run, we did not finish flushing all ancestral
Expand Down
4 changes: 3 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func SetupRunFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Bool("force-checksum", true, "When true, the node will panic if the "+
"local state checksum differs from the network checksum reported by its peers.")
// Snapshot
cmd.PersistentFlags().Uint64("snapshot-block-height-period", 1000, "Set the snapshot epoch period. Snapshots are taken at block heights divisible by the period.")
cmd.PersistentFlags().Uint64("snapshot-block-height-period", 600000, "Set the snapshot epoch period. Snapshots are taken at block heights divisible by the period.")
// Archival mode
cmd.PersistentFlags().Bool("archival-mode", true, "Download all historical blocks after finishing hypersync.")
// Disable encoder migrations
Expand Down Expand Up @@ -222,6 +222,8 @@ func SetupRunFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Bool("time-events", false, "Enable simple event timer, helpful in hands-on performance testing")
cmd.PersistentFlags().String("state-change-dir", "", "The directory for state change logs. WARNING: Changing this "+
"from an empty string to a non-empty string (or from a non-empty string to the empty string) requires a resync.")
cmd.PersistentFlags().Uint("state-syncer-mempool-txn-sync-limit", 10000, "The maximum number of transactions to "+
"process in the mempool tx state syncer at a time.")
cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
viper.BindPFlag(flag.Name, flag)
})
Expand Down
80 changes: 80 additions & 0 deletions collections/concurrent_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package collections

import "sync"

type ConcurrentMap[Key comparable, Value any] struct {
mtx sync.RWMutex
m map[Key]Value
}

func NewConcurrentMap[Key comparable, Value any]() *ConcurrentMap[Key, Value] {
return &ConcurrentMap[Key, Value]{
m: make(map[Key]Value),
}
}

func (cm *ConcurrentMap[Key, Value]) Set(key Key, val Value) {
cm.mtx.Lock()
defer cm.mtx.Unlock()

cm.m[key] = val
}

func (cm *ConcurrentMap[Key, Value]) Remove(key Key) {
cm.mtx.Lock()
defer cm.mtx.Unlock()

_, ok := cm.m[key]
if !ok {
return
}
delete(cm.m, key)
}

func (cm *ConcurrentMap[Key, Value]) Get(key Key) (Value, bool) {
cm.mtx.RLock()
defer cm.mtx.RUnlock()

val, ok := cm.m[key]
return val, ok
}

func (cm *ConcurrentMap[Key, Value]) Clone() *ConcurrentMap[Key, Value] {
cm.mtx.RLock()
defer cm.mtx.RUnlock()

clone := NewConcurrentMap[Key, Value]()
for key, val := range cm.m {
clone.Set(key, val)
}
return clone
}

func (cm *ConcurrentMap[Key, Value]) ToMap() map[Key]Value {
cm.mtx.RLock()
defer cm.mtx.RUnlock()

index := make(map[Key]Value)
for key, node := range cm.m {
index[key] = node
}
return index
}

func (cm *ConcurrentMap[Key, Value]) GetAll() []Value {
cm.mtx.RLock()
defer cm.mtx.RUnlock()

var vals []Value
for _, val := range cm.m {
vals = append(vals, val)
}
return vals
}

func (cm *ConcurrentMap[Key, Value]) Count() int {
cm.mtx.RLock()
defer cm.mtx.RUnlock()

return len(cm.m)
}
61 changes: 61 additions & 0 deletions collections/concurrent_map_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package collections

import (
"fmt"
"testing"
)

func TestConcurrentMap(t *testing.T) {
m := NewConcurrentMap[string, int]()
control := make(map[string]int)

// test add
for ii := 0; ii < 100; ii++ {
key := fmt.Sprintf("%v", ii)
m.Set(key, ii)
control[key] = ii
}

for key, val := range control {
if mVal, ok := m.Get(key); !ok || mVal != val {
t.Errorf("Expected %d, got %d", val, m.m[key])
}
}

// test remove
for ii := 0; ii < 50; ii++ {
key := fmt.Sprintf("%v", ii)
m.Remove(key)
delete(control, key)
}

for key, val := range control {
if mVal, ok := m.Get(key); !ok || mVal != val {
t.Errorf("Expected %d, got %d", val, m.m[key])
}
}

// test copy
copy := m.ToMap()
for key, val := range control {
if mVal, ok := copy[key]; !ok || mVal != val {
t.Errorf("Expected %d, got %d", val, m.m[key])
}
}
if len(copy) != len(control) {
t.Errorf("Expected %d, got %d", len(control), len(copy))
}

// test get all
vals := m.GetAll()
for _, val := range vals {
if _, ok := control[fmt.Sprintf("%v", val)]; !ok {
t.Errorf("Expected %d, got %d", val, m.m[fmt.Sprintf("%v", val)])
}
}

// test size
if m.Count() != len(control) {
t.Errorf("Expected %d, got %d", len(control), m.Count())
}
}
4 changes: 4 additions & 0 deletions consensus/integration_test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (node *validatorNode) GetStakeAmount() *uint256.Int {
return node.stake
}

func (node *validatorNode) GetDomains() [][]byte {
return [][]byte{}
}

func (node *validatorNode) ProcessBlock(incomingBlock *block) {
node.lock.Lock()
defer node.lock.Unlock()
Expand Down
1 change: 1 addition & 0 deletions consensus/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type BlockHash interface {
type Validator interface {
GetPublicKey() *bls.PublicKey
GetStakeAmount() *uint256.Int
GetDomains() [][]byte
}

type AggregateQuorumCertificate interface {
Expand Down
4 changes: 4 additions & 0 deletions consensus/types_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (v *validator) GetStakeAmount() *uint256.Int {
return v.stakeAmount
}

func (v *validator) GetDomains() [][]byte {
return [][]byte{}
}

////////////////////////////////////////////////////////////////////////
// AggregateQuorumCertificate interface implementation for internal use.
// We use this type for unit tests, and to construct timeout QCs for
Expand Down
Loading
Loading