mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-26 08:35:17 +00:00
2bbd1e0690
* Remove bootstrap peer (#189) * Change bootstrap servers to DHT-only peers (#187) * support voucher file-based claims (#183) * Change bootstrap servers to DHT-only peers Changing my bootstrap servers to DHT-only peers with somewhat lower specs. One of the new ones is in the US and the other one is in Switzerland. Both use reliable providers and have 10Gbps network interfaces. --------- Co-authored-by: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com> * Don't run self-test in DHT-only mode (#186) * support voucher file-based claims (#183) * Don't run self-test in DHT-only mode The node tries to create a self-test when ran with the `-dht-only` flag, but it doesn't load the KZG ceremony data in DHT-only mode which leads to a crash. Don't run self-test when the `-dht-only` flag is set. I tested by starting a node locally with and without existing self-test and with the `-dht-only` flag. --------- Co-authored-by: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com> * Embed json files in binary (#182) * Embed ceremony.json in binary * Embed retroactive_peers.json in binary * Signers build and verification tasks (#181) * add signers specific Taskfile * add verify tasks * move signer task under signer folder * create docker image specific for signers * map current user into docker image and container * ignore node-tmp-* * add verify:build:internal * prevent tasks with docker commands from being run inside a container * rename *:internal to *:container * add README.md * add pem files to git * Updating Q Guide link (#173) * Update README.md Updated link to Quilibrium guide to new website * Update README.md * feat: network switching and namespaced announce strings/bitmasks (#190) * feat: network switching and namespaced announce strings/bitmasks * bump version name and logo * feat: mini pomw proofs as part of peer manifest (#191) * shift default config directory under current folder (#176) * feat: signature check (#192) * feat: signature check * adjust docker command so it doesn't invoke sigcheck * remove old version * add binaries and digests * fix bug, revert build * shasum has weird byte at end * proper binaries and digests * Signatory #13 added * Signatory #3 added * Signer 4 (#194) * Signatory #5 added * Signatory #9 added (#195) * Signatory #1 added * added sig.6 files (#196) * Signatories #8 and #16 added * Signatory #12 added * Add signature (#197) * reset build for v1.4.18 after testnet bug * updated build, resigned by #13 * Signatory #16 added * added sig.6 files (#198) * Signatory #8 added * Signatory #17 added * Signatory #1 added * Signatory #7 added * Signatory #4 added * Signatory #14 added * remove binaries, ready to ship --------- Co-authored-by: littleblackcloud <163544315+littleblackcloud@users.noreply.github.com> Co-authored-by: Agost Biro <5764438+agostbiro@users.noreply.github.com> Co-authored-by: Marius Scurtescu <marius.scurtescu@gmail.com> Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com> Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com> Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
152 lines
3.2 KiB
Go
152 lines
3.2 KiB
Go
package master
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/mr-tron/base58"
|
|
"github.com/pkg/errors"
|
|
"go.uber.org/zap"
|
|
"source.quilibrium.com/quilibrium/monorepo/node/consensus"
|
|
"source.quilibrium.com/quilibrium/monorepo/node/p2p"
|
|
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
|
)
|
|
|
|
func (e *MasterClockConsensusEngine) prove(
|
|
previousFrame *protobufs.ClockFrame,
|
|
) (*protobufs.ClockFrame, error) {
|
|
e.logger.Debug("proving new frame")
|
|
|
|
frame, err := e.frameProver.ProveMasterClockFrame(
|
|
previousFrame,
|
|
time.Now().UnixMilli(),
|
|
e.difficulty,
|
|
)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "prove")
|
|
}
|
|
|
|
e.state = consensus.EngineStatePublishing
|
|
e.logger.Debug("returning new proven frame")
|
|
return frame, nil
|
|
}
|
|
|
|
func (e *MasterClockConsensusEngine) GetMostAheadPeers() (
|
|
[][]byte,
|
|
error,
|
|
) {
|
|
frame, err := e.masterTimeReel.Head()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Needs to be enough to make the sync worthwhile:
|
|
max := frame.FrameNumber + 10
|
|
|
|
var peers [][]byte = [][]byte{}
|
|
peerMap := e.peerInfoManager.GetPeerMap()
|
|
for peerId, v := range peerMap {
|
|
if v.MasterHeadFrame > max {
|
|
peers = append(peers, []byte(peerId))
|
|
}
|
|
|
|
if len(peers) >= 30 {
|
|
break
|
|
}
|
|
}
|
|
|
|
if len(peers) == 0 {
|
|
return nil, p2p.ErrNoPeersAvailable
|
|
}
|
|
|
|
return peers, nil
|
|
}
|
|
|
|
func (e *MasterClockConsensusEngine) collect(
|
|
currentFramePublished *protobufs.ClockFrame,
|
|
) (*protobufs.ClockFrame, error) {
|
|
e.logger.Debug("collecting vdf proofs")
|
|
|
|
latest, err := e.masterTimeReel.Head()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// With the increase of network size, constrain down to top thirty
|
|
peers, err := e.GetMostAheadPeers()
|
|
if err != nil {
|
|
return latest, nil
|
|
}
|
|
|
|
for i := 0; i < len(peers); i++ {
|
|
peer := peers[i]
|
|
e.logger.Info("setting syncing target", zap.Binary("peer_id", peer))
|
|
|
|
cc, err := e.pubSub.GetDirectChannel(peer, "validation")
|
|
if err != nil {
|
|
e.logger.Error(
|
|
"could not connect for sync",
|
|
zap.String("peer_id", base58.Encode(peer)),
|
|
)
|
|
continue
|
|
}
|
|
client := protobufs.NewValidationServiceClient(cc)
|
|
syncClient, err := client.Sync(
|
|
context.Background(),
|
|
&protobufs.SyncRequest{
|
|
FramesRequest: &protobufs.ClockFramesRequest{
|
|
Filter: e.filter,
|
|
FromFrameNumber: latest.FrameNumber,
|
|
ToFrameNumber: 0,
|
|
},
|
|
},
|
|
)
|
|
if err != nil {
|
|
cc.Close()
|
|
continue
|
|
}
|
|
|
|
for msg, err := syncClient.Recv(); msg != nil &&
|
|
err == nil; msg, err = syncClient.Recv() {
|
|
if msg.FramesResponse == nil {
|
|
break
|
|
}
|
|
|
|
for _, frame := range msg.FramesResponse.ClockFrames {
|
|
frame := frame
|
|
|
|
if frame.FrameNumber < latest.FrameNumber {
|
|
continue
|
|
}
|
|
|
|
if e.difficulty != frame.Difficulty {
|
|
e.logger.Debug(
|
|
"frame difficulty mismatched",
|
|
zap.Uint32("difficulty", frame.Difficulty),
|
|
)
|
|
break
|
|
}
|
|
|
|
if err := e.frameProver.VerifyMasterClockFrame(frame); err != nil {
|
|
e.logger.Error(
|
|
"peer returned invalid frame",
|
|
zap.String("peer_id", base58.Encode(peer)))
|
|
e.pubSub.SetPeerScore(peer, -1000)
|
|
break
|
|
}
|
|
|
|
e.masterTimeReel.Insert(frame, false)
|
|
latest = frame
|
|
}
|
|
}
|
|
if err != nil {
|
|
cc.Close()
|
|
break
|
|
}
|
|
cc.Close()
|
|
break
|
|
}
|
|
|
|
return latest, nil
|
|
}
|