ceremonyclient/node/app/node.go

205 lines
4.2 KiB
Go
Raw Normal View History

2023-09-03 23:47:09 +00:00
package app
import (
"encoding/binary"
2023-09-03 23:47:09 +00:00
"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
2024-10-14 21:39:52 +00:00
coinStore store.CoinStore
2024-06-08 11:32:45 +00:00
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,
2024-10-14 21:39:52 +00:00
coinStore store.CoinStore,
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,
2024-10-14 21:39:52 +00:00
coinStore,
2023-10-28 02:23:55 +00:00
keyManager,
pubSub,
2023-09-03 23:47:09 +00:00
execEngines,
engine,
}, nil
}
func GetOutputs(output []byte) (
index uint32,
indexProof []byte,
kzgCommitment []byte,
kzgProof []byte,
) {
index = binary.BigEndian.Uint32(output[:4])
indexProof = output[4:520]
kzgCommitment = output[520:594]
kzgProof = output[594:668]
return index, indexProof, kzgCommitment, kzgProof
}
2024-10-14 01:37:19 +00:00
func nearestApplicablePowerOfTwo(number uint64) uint64 {
power := uint64(128)
if number > 2048 {
power = 65536
} else if number > 1024 {
power = 2048
} else if number > 128 {
power = 1024
}
return power
}
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)
}
2024-07-29 17:46:36 +00:00
2024-06-08 11:32:45 +00:00
dataProver := crypto.NewKZGInclusionProver(n.logger)
wesoProver := crypto.NewWesolowskiFrameProver(n.logger)
for j := int(i); j >= 0; j-- {
fmt.Println(j)
_, parallelism, input, o, err := n.dataProofStore.GetDataTimeProof(n.pubSub.GetPeerID(), uint32(j))
2024-06-08 11:32:45 +00:00
if err != nil {
panic(err)
}
idx, idxProof, idxCommit, idxKP := GetOutputs(o)
2024-06-08 11:32:45 +00:00
ip := sha3.Sum512(idxProof)
v, err := dataProver.VerifyRaw(
ip[:],
idxCommit,
int(idx),
idxKP,
2024-10-14 01:37:19 +00:00
nearestApplicablePowerOfTwo(uint64(parallelism)),
)
2024-06-08 11:32:45 +00:00
if err != nil {
panic(err)
}
if !v {
2024-07-29 17:46:36 +00:00
panic(fmt.Sprintf("bad kzg proof at increment %d", j))
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.VerifyPreDuskChallengeProof(wp, uint32(j), idx, idxProof)
2024-06-08 11:32:45 +00:00
if !v {
2024-07-29 17:46:36 +00:00
panic(fmt.Sprintf("bad weso proof at increment %d", j))
2024-03-08 05:05:04 +00:00
}
}
2024-06-08 11:32:45 +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-10-14 21:39:52 +00:00
func (n *Node) GetCoinStore() store.CoinStore {
return n.coinStore
}
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
}