ceremonyclient/node/app/node.go

239 lines
5.3 KiB
Go
Raw Normal View History

2023-09-03 23:47:09 +00:00
package app
import (
"errors"
2024-06-08 11:32:45 +00:00
"fmt"
2023-09-03 23:47:09 +00:00
"go.uber.org/zap"
2024-06-08 11:32:45 +00:00
"golang.org/x/crypto/sha3"
2023-09-03 23:47:09 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/consensus"
2024-03-04 03:20:24 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/consensus/master"
2024-06-08 11:32:45 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/crypto"
2023-09-03 23:47:09 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/execution"
2023-10-28 02:23:55 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/keys"
"source.quilibrium.com/quilibrium/monorepo/node/p2p"
"source.quilibrium.com/quilibrium/monorepo/node/store"
2023-09-03 23:47:09 +00:00
)
type Node struct {
2024-06-08 11:32:45 +00:00
logger *zap.Logger
dataProofStore store.DataProofStore
clockStore store.ClockStore
keyManager keys.KeyManager
pubSub p2p.PubSub
execEngines map[string]execution.ExecutionEngine
engine consensus.ConsensusEngine
2023-09-03 23:47:09 +00:00
}
type DHTNode struct {
pubSub p2p.PubSub
quit chan struct{}
}
func newDHTNode(
pubSub p2p.PubSub,
) (*DHTNode, error) {
return &DHTNode{
pubSub: pubSub,
quit: make(chan struct{}),
}, nil
}
2023-09-03 23:47:09 +00:00
func newNode(
logger *zap.Logger,
2024-06-08 11:32:45 +00:00
dataProofStore store.DataProofStore,
clockStore store.ClockStore,
2023-10-28 02:23:55 +00:00
keyManager keys.KeyManager,
pubSub p2p.PubSub,
v1.4.18 (#193) * 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>
2024-05-25 05:22:50 +00:00
// execution engines wire in here
2023-09-03 23:47:09 +00:00
engine consensus.ConsensusEngine,
) (*Node, error) {
if engine == nil {
return nil, errors.New("engine must not be nil")
}
execEngines := make(map[string]execution.ExecutionEngine)
return &Node{
logger,
2024-06-08 11:32:45 +00:00
dataProofStore,
clockStore,
2023-10-28 02:23:55 +00:00
keyManager,
pubSub,
2023-09-03 23:47:09 +00:00
execEngines,
engine,
}, nil
}
2024-06-08 11:32:45 +00:00
func (n *Node) VerifyProofIntegrity() {
i, _, _, e := n.dataProofStore.GetLatestDataTimeProof(n.pubSub.GetPeerID())
if e != nil {
panic(e)
}
dataProver := crypto.NewKZGInclusionProver(n.logger)
wesoProver := crypto.NewWesolowskiFrameProver(n.logger)
for j := int(i); j >= 0; j-- {
fmt.Println(j)
_, _, input, o, err := n.dataProofStore.GetDataTimeProof(n.pubSub.GetPeerID(), uint32(j))
if err != nil {
panic(err)
}
idx, idxProof, idxCommit, idxKP := master.GetOutputs(o)
ip := sha3.Sum512(idxProof)
v, err := dataProver.VerifyRaw(ip[:], idxCommit, int(idx), idxKP, 128)
if err != nil {
panic(err)
}
if !v {
panic(fmt.Sprintf("bad kzg proof at increment %d", i))
2024-06-08 11:32:45 +00:00
}
wp := []byte{}
wp = append(wp, n.pubSub.GetPeerID()...)
wp = append(wp, input...)
fmt.Printf("%x\n", wp)
v = wesoProver.VerifyChallengeProof(wp, uint32(j), idx, idxProof)
if !v {
panic(fmt.Sprintf("bad weso proof at increment %d", i))
2024-03-08 05:05:04 +00:00
}
}
2024-06-08 11:32:45 +00:00
}
func (n *Node) RunRepair() {
// intrinsicFilter := append(
// p2p.GetBloomFilter(application.CEREMONY_ADDRESS, 256, 3),
// p2p.GetBloomFilterIndices(application.CEREMONY_ADDRESS, 65536, 24)...,
// )
// n.logger.Info("check store and repair if needed, this may take a few minutes")
// proverTrie := &tries.RollingFrecencyCritbitTrie{}
// head, err := n.clockStore.GetLatestDataClockFrame(intrinsicFilter, proverTrie)
// if err == nil && head != nil {
// for head != nil && head.FrameNumber != 0 {
// prev := head
// head, err = n.clockStore.GetStagedDataClockFrame(
// intrinsicFilter,
// head.FrameNumber-1,
// head.ParentSelector,
// true,
// )
// if err != nil {
// panic(err)
// }
// compare, _, err := n.clockStore.GetDataClockFrame(
// intrinsicFilter,
// prev.FrameNumber-1,
// true,
// )
// if err != nil {
// panic(err)
// }
// if !bytes.Equal(head.Output, compare.Output) {
// n.logger.Warn(
// "repairing frame",
// zap.Uint64("frame_number", head.FrameNumber),
// )
// head, err = n.clockStore.GetStagedDataClockFrame(
// intrinsicFilter,
// prev.FrameNumber-1,
// prev.ParentSelector,
// true,
// )
// if err != nil {
// panic(err)
// }
// txn, err := n.clockStore.NewTransaction()
// if err != nil {
// panic(err)
// }
// selector, err := head.GetSelector()
// if err != nil {
// panic(err)
// }
// err = n.clockStore.CommitDataClockFrame(
// intrinsicFilter,
// head.FrameNumber,
// selector.FillBytes(make([]byte, 32)),
// proverTrie,
// txn,
// true,
// )
// if err != nil {
// panic(err)
// }
// if err = txn.Commit(); err != nil {
// panic(err)
// }
// }
// }
// }
// n.logger.Info("check complete")
2024-03-08 05:05:04 +00:00
}
func (d *DHTNode) Start() {
<-d.quit
}
func (d *DHTNode) Stop() {
go func() {
d.quit <- struct{}{}
}()
}
2023-09-03 23:47:09 +00:00
func (n *Node) Start() {
err := <-n.engine.Start()
if err != nil {
panic(err)
}
// TODO: add config mapping to engine name/frame registration
for _, e := range n.execEngines {
n.engine.RegisterExecutor(e, 0)
}
}
func (n *Node) Stop() {
err := <-n.engine.Stop(false)
if err != nil {
panic(err)
}
}
func (n *Node) GetLogger() *zap.Logger {
return n.logger
}
func (n *Node) GetClockStore() store.ClockStore {
return n.clockStore
}
2024-06-08 11:32:45 +00:00
func (n *Node) GetDataProofStore() store.DataProofStore {
return n.dataProofStore
}
2023-10-28 02:23:55 +00:00
func (n *Node) GetKeyManager() keys.KeyManager {
return n.keyManager
}
func (n *Node) GetPubSub() p2p.PubSub {
return n.pubSub
}
2024-03-04 03:20:24 +00:00
func (n *Node) GetMasterClock() *master.MasterClockConsensusEngine {
return n.engine.(*master.MasterClockConsensusEngine)
}
func (n *Node) GetExecutionEngines() []execution.ExecutionEngine {
list := []execution.ExecutionEngine{}
for _, e := range n.execEngines {
list = append(list, e)
}
return list
}