mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-11-10 18:25:17 +00:00
extract version logic to config package (#107)
* Modify the wrong default volumes value to /root/.config (#109) * move extract version logic to new version.go in config package * update version extraction command --------- Co-authored-by: talentbuilder <talentbuilder@163.com>
This commit is contained in:
parent
fe0e6531bf
commit
d6460bc521
@ -7,7 +7,7 @@ dotenv:
|
||||
|
||||
vars:
|
||||
VERSION:
|
||||
sh: cat node/main.go | grep "Quilibrium Node - v" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'
|
||||
sh: cat node/config/version.go | grep -A 1 "func GetVersion() \[\]byte {" | grep -Eo '0x[0-9a-fA-F]+' | xargs printf "%d.%d.%d"
|
||||
PROJECT_NAME: quilibrium
|
||||
SERVICE_NAME: node
|
||||
GIT_REPO:
|
||||
|
@ -887,11 +887,11 @@ func logoVersion(width int) string {
|
||||
out += " ''---.. ...---'' ##\n"
|
||||
out += " ''----------''\n"
|
||||
out += " \n"
|
||||
out += " Quilibrium Node - v1.4.6 – Sunset\n"
|
||||
out += " Quilibrium Node - v" + config.GetVersionString() + " – Sunset\n"
|
||||
out += " \n"
|
||||
out += " DB Console\n"
|
||||
} else {
|
||||
out = "Quilibrium Node - v1.4.6 – Sunset - DB Console\n"
|
||||
out = "Quilibrium Node - v" + config.GetVersionString() + " – Sunset - DB Console\n"
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
22
node/config/version.go
Normal file
22
node/config/version.go
Normal file
@ -0,0 +1,22 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetMinimumVersionCutoff() time.Time {
|
||||
return time.Date(2024, time.March, 10, 5, 30, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
func GetMinimumVersion() []byte {
|
||||
return []byte{0x01, 0x04, 0x05}
|
||||
}
|
||||
|
||||
func GetVersion() []byte {
|
||||
return []byte{0x01, 0x04, 0x06}
|
||||
}
|
||||
|
||||
func GetVersionString() string {
|
||||
return fmt.Sprintf("%d.%d.%d", GetVersion()[0], GetVersion()[1], GetVersion()[2])
|
||||
}
|
47
node/config/version_test.go
Normal file
47
node/config/version_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGetMinimumVersion(t *testing.T) {
|
||||
minVersion := GetMinimumVersion()
|
||||
|
||||
assert.Equal(t, 3, len(minVersion), "Expected version to have exactly 3 bytes; got %v", len(minVersion))
|
||||
|
||||
version := GetVersion()
|
||||
|
||||
assert.GreaterOrEqual(t, version[0], minVersion[0])
|
||||
|
||||
if minVersion[0] == version[0] {
|
||||
assert.GreaterOrEqual(t, version[1], minVersion[1])
|
||||
|
||||
if minVersion[1] == version[1] {
|
||||
assert.GreaterOrEqual(t, version[2], minVersion[2])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVersion(t *testing.T) {
|
||||
version := GetVersion()
|
||||
|
||||
assert.Equal(t, 3, len(version), "Expected version to have exactly 3 bytes; got %v", len(version))
|
||||
}
|
||||
|
||||
func TestGetMinimumVersionCutoff(t *testing.T) {
|
||||
cutoff := GetMinimumVersionCutoff()
|
||||
|
||||
assert.True(t, cutoff.Before(time.Now()))
|
||||
assert.True(t, cutoff.After(time.Date(2024, time.March, 1, 0, 0, 0, 0, time.UTC)))
|
||||
}
|
||||
|
||||
func TestGetVersionString(t *testing.T) {
|
||||
version := GetVersionString()
|
||||
|
||||
versionRegexp := regexp.MustCompile("[0-9]+\\.[0-9]+\\.[0-9]+")
|
||||
|
||||
assert.Regexp(t, versionRegexp, version)
|
||||
}
|
@ -3,6 +3,7 @@ package ceremony
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -15,7 +16,6 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"source.quilibrium.com/quilibrium/monorepo/go-libp2p-blossomsub/pb"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/consensus"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/keys"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
||||
)
|
||||
@ -98,7 +98,7 @@ func (e *CeremonyDataClockConsensusEngine) handleMessage(
|
||||
case protobufs.ClockFrameType:
|
||||
e.peerMapMx.RLock()
|
||||
if peer, ok := e.peerMap[string(message.From)]; !ok ||
|
||||
bytes.Compare(peer.version, consensus.GetMinimumVersion()) < 0 {
|
||||
bytes.Compare(peer.version, config.GetMinimumVersion()) < 0 {
|
||||
return nil
|
||||
}
|
||||
e.peerMapMx.RUnlock()
|
||||
@ -179,8 +179,8 @@ func (e *CeremonyDataClockConsensusEngine) handleCeremonyPeerListAnnounce(
|
||||
continue
|
||||
}
|
||||
|
||||
if bytes.Compare(p.Version, consensus.GetMinimumVersion()) < 0 &&
|
||||
p.Timestamp > consensus.GetMinimumVersionCutoff().UnixMilli() {
|
||||
if bytes.Compare(p.Version, config.GetMinimumVersion()) < 0 &&
|
||||
p.Timestamp > config.GetMinimumVersionCutoff().UnixMilli() {
|
||||
e.logger.Debug(
|
||||
"peer provided outdated version, penalizing app score",
|
||||
zap.Binary("peer_id", p.PeerId),
|
||||
|
@ -313,7 +313,7 @@ func (e *CeremonyDataClockConsensusEngine) Start() <-chan error {
|
||||
|
||||
timestamp := time.Now().UnixMilli()
|
||||
msg := binary.BigEndian.AppendUint64([]byte{}, frame.FrameNumber)
|
||||
msg = append(msg, consensus.GetVersion()...)
|
||||
msg = append(msg, config.GetVersion()...)
|
||||
msg = binary.BigEndian.AppendUint64(msg, uint64(timestamp))
|
||||
sig, err := e.pubSub.SignMessage(msg)
|
||||
if err != nil {
|
||||
@ -325,7 +325,7 @@ func (e *CeremonyDataClockConsensusEngine) Start() <-chan error {
|
||||
peerId: e.pubSub.GetPeerID(),
|
||||
multiaddr: "",
|
||||
maxFrame: frame.FrameNumber,
|
||||
version: consensus.GetVersion(),
|
||||
version: config.GetVersion(),
|
||||
signature: sig,
|
||||
publicKey: e.pubSub.GetPublicKey(),
|
||||
timestamp: timestamp,
|
||||
@ -338,7 +338,7 @@ func (e *CeremonyDataClockConsensusEngine) Start() <-chan error {
|
||||
PeerId: e.pubSub.GetPeerID(),
|
||||
Multiaddr: "",
|
||||
MaxFrame: frame.FrameNumber,
|
||||
Version: consensus.GetVersion(),
|
||||
Version: config.GetVersion(),
|
||||
Signature: sig,
|
||||
PublicKey: e.pubSub.GetPublicKey(),
|
||||
Timestamp: timestamp,
|
||||
@ -369,7 +369,7 @@ func (e *CeremonyDataClockConsensusEngine) Start() <-chan error {
|
||||
PeerId: e.pubSub.GetPeerID(),
|
||||
Multiaddrs: []string{""},
|
||||
MaxFrame: frame.FrameNumber,
|
||||
Version: consensus.GetVersion(),
|
||||
Version: config.GetVersion(),
|
||||
Signature: sig,
|
||||
PublicKey: e.pubSub.GetPublicKey(),
|
||||
Timestamp: timestamp,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -163,8 +164,8 @@ func (e *CeremonyDataClockConsensusEngine) GetMostAheadPeer() (
|
||||
for _, v := range e.peerMap {
|
||||
_, ok := e.uncooperativePeersMap[string(v.peerId)]
|
||||
if v.maxFrame > max &&
|
||||
v.timestamp > consensus.GetMinimumVersionCutoff().UnixMilli() &&
|
||||
bytes.Compare(v.version, consensus.GetMinimumVersion()) >= 0 && !ok {
|
||||
v.timestamp > config.GetMinimumVersionCutoff().UnixMilli() &&
|
||||
bytes.Compare(v.version, config.GetMinimumVersion()) >= 0 && !ok {
|
||||
peer = v.peerId
|
||||
max = v.maxFrame
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package consensus
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"time"
|
||||
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/execution"
|
||||
"source.quilibrium.com/quilibrium/monorepo/node/keys"
|
||||
@ -49,15 +47,3 @@ type DataConsensusEngine interface {
|
||||
IsInProverTrie(key []byte) bool
|
||||
GetPeerInfo() *protobufs.PeerInfoResponse
|
||||
}
|
||||
|
||||
func GetMinimumVersionCutoff() time.Time {
|
||||
return time.Date(2024, time.March, 10, 5, 30, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
func GetMinimumVersion() []byte {
|
||||
return []byte{0x01, 0x04, 0x05}
|
||||
}
|
||||
|
||||
func GetVersion() []byte {
|
||||
return []byte{0x01, 0x04, 0x06}
|
||||
}
|
||||
|
@ -491,5 +491,5 @@ func printLogo() {
|
||||
|
||||
func printVersion() {
|
||||
fmt.Println(" ")
|
||||
fmt.Println(" Quilibrium Node - v1.4.6 – Sunset")
|
||||
fmt.Println(" Quilibrium Node - v" + config.GetVersionString() + " – Sunset")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user