Fix mongo types in Fly
This commit is contained in:
parent
43c529e5d3
commit
99e895d600
|
@ -8,6 +8,18 @@ spec:
|
|||
metadata:
|
||||
name: mongo-rs-config
|
||||
spec:
|
||||
initContainers:
|
||||
- name: init-mongodb
|
||||
image: mongo:latest
|
||||
command:
|
||||
- /bin/bash
|
||||
- -c
|
||||
- |-
|
||||
until mongosh --eval 'db.runCommand("ping").ok' mongo-0.mongo:27017/test --quiet;
|
||||
do
|
||||
echo "**** Waiting for MongoDB ...";
|
||||
sleep 5;
|
||||
done
|
||||
containers:
|
||||
- name: mongo
|
||||
image: mongo:latest
|
||||
|
|
|
@ -67,19 +67,39 @@ type GovernorStatusUpdate struct {
|
|||
|
||||
type ChainGovernorStatusChain struct {
|
||||
ChainId uint32 `bson:"chainid"`
|
||||
RemainingAvailableNotional uint64 `bson:"remainingavailablenotional"`
|
||||
RemainingAvailableNotional Uint64 `bson:"remainingavailablenotional"`
|
||||
Emitters []*ChainGovernorStatusEmitter `bson:"emitters"`
|
||||
}
|
||||
|
||||
type ChainGovernorStatusEmitter struct {
|
||||
EmitterAddress string `bson:"emitteraddress"`
|
||||
TotalEnqueuedVaas uint64 `bson:"totalenqueuedvaas"`
|
||||
TotalEnqueuedVaas Uint64 `bson:"totalenqueuedvaas"`
|
||||
EnqueuedVaas []*ChainGovernorStatusEnqueuedVAA `bson:"enqueuedvaas"`
|
||||
}
|
||||
|
||||
type ChainGovernorStatusEnqueuedVAA struct {
|
||||
Sequence string `bson:"sequence"`
|
||||
ReleaseTime uint32 `bson:"releasetime"`
|
||||
NotionalValue uint64 `bson:"notionalvalue"`
|
||||
NotionalValue Uint64 `bson:"notionalvalue"`
|
||||
TxHash string `bson:"txhash"`
|
||||
}
|
||||
|
||||
type ChainGovernorConfigUpdate struct {
|
||||
NodeName string
|
||||
Counter int64
|
||||
Timestamp int64
|
||||
Chains []*ChainGovernorConfigChain
|
||||
Tokens []*ChainGovernorConfigToken
|
||||
}
|
||||
|
||||
type ChainGovernorConfigChain struct {
|
||||
ChainId uint32
|
||||
NotionalLimit Uint64
|
||||
BigTransactionSize Uint64
|
||||
}
|
||||
|
||||
type ChainGovernorConfigToken struct {
|
||||
OriginChainId uint32
|
||||
OriginAddress string
|
||||
Price float32
|
||||
}
|
||||
|
|
|
@ -138,13 +138,17 @@ func (s *Repository) UpsertHeartbeat(hb *gossipv1.Heartbeat) error {
|
|||
func (s *Repository) UpsertGovernorConfig(govC *gossipv1.SignedChainGovernorConfig) error {
|
||||
id := hex.EncodeToString(govC.GuardianAddr)
|
||||
now := time.Now()
|
||||
var cfg gossipv1.ChainGovernorConfig
|
||||
err := proto.Unmarshal(govC.Config, &cfg)
|
||||
var gCfg gossipv1.ChainGovernorConfig
|
||||
err := proto.Unmarshal(govC.Config, &gCfg)
|
||||
if err != nil {
|
||||
s.log.Error("Error unmarshalling govr config", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
cfg := toGovernorConfigUpdate(&gCfg)
|
||||
|
||||
update := bson.D{{Key: "$set", Value: govC}, {Key: "$set", Value: bson.D{{Key: "parsedConfig", Value: cfg}}}, {Key: "$set", Value: bson.D{{Key: "updatedAt", Value: now}}}, {Key: "$setOnInsert", Value: bson.D{{Key: "createdAt", Value: now}}}}
|
||||
|
||||
opts := options.Update().SetUpsert(true)
|
||||
_, err2 := s.collections.governorConfig.UpdateByID(context.TODO(), id, update, opts)
|
||||
|
||||
|
@ -178,7 +182,7 @@ func (s *Repository) UpsertGovernorStatus(govS *gossipv1.SignedChainGovernorStat
|
|||
}
|
||||
|
||||
func (s *Repository) updateVAACount(chainID vaa.ChainID) {
|
||||
update := bson.D{{Key: "$inc", Value: bson.D{{Key: "count", Value: 1}}}}
|
||||
update := bson.D{{Key: "$inc", Value: bson.D{{Key: "count", Value: uint64(1)}}}}
|
||||
opts := options.Update().SetUpsert(true)
|
||||
_, _ = s.collections.vaaCounts.UpdateByID(context.TODO(), chainID, update, opts)
|
||||
}
|
||||
|
@ -213,7 +217,7 @@ func toGovernorStatusUpdate(s *gossipv1.ChainGovernorStatus) *GovernorStatusUpda
|
|||
enqueuedVaa := &ChainGovernorStatusEnqueuedVAA{
|
||||
Sequence: strconv.FormatUint(ev.Sequence, 10),
|
||||
ReleaseTime: ev.ReleaseTime,
|
||||
NotionalValue: ev.NotionalValue,
|
||||
NotionalValue: Uint64(ev.NotionalValue),
|
||||
TxHash: ev.TxHash,
|
||||
}
|
||||
enqueuedVaas = append(enqueuedVaas, enqueuedVaa)
|
||||
|
@ -221,7 +225,7 @@ func toGovernorStatusUpdate(s *gossipv1.ChainGovernorStatus) *GovernorStatusUpda
|
|||
|
||||
emitter := &ChainGovernorStatusEmitter{
|
||||
EmitterAddress: e.EmitterAddress,
|
||||
TotalEnqueuedVaas: e.TotalEnqueuedVaas,
|
||||
TotalEnqueuedVaas: Uint64(e.TotalEnqueuedVaas),
|
||||
EnqueuedVaas: enqueuedVaas,
|
||||
}
|
||||
emitters = append(emitters, emitter)
|
||||
|
@ -229,7 +233,7 @@ func toGovernorStatusUpdate(s *gossipv1.ChainGovernorStatus) *GovernorStatusUpda
|
|||
|
||||
chain := &ChainGovernorStatusChain{
|
||||
ChainId: c.ChainId,
|
||||
RemainingAvailableNotional: c.RemainingAvailableNotional,
|
||||
RemainingAvailableNotional: Uint64(c.RemainingAvailableNotional),
|
||||
Emitters: emitters,
|
||||
}
|
||||
chains = append(chains, chain)
|
||||
|
@ -243,3 +247,34 @@ func toGovernorStatusUpdate(s *gossipv1.ChainGovernorStatus) *GovernorStatusUpda
|
|||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func toGovernorConfigUpdate(c *gossipv1.ChainGovernorConfig) *ChainGovernorConfigUpdate {
|
||||
|
||||
var chains []*ChainGovernorConfigChain
|
||||
for _, c := range c.Chains {
|
||||
chain := &ChainGovernorConfigChain{
|
||||
ChainId: c.ChainId,
|
||||
NotionalLimit: Uint64(c.NotionalLimit),
|
||||
BigTransactionSize: Uint64(c.BigTransactionSize),
|
||||
}
|
||||
chains = append(chains, chain)
|
||||
}
|
||||
|
||||
var tokens []*ChainGovernorConfigToken
|
||||
for _, t := range c.Tokens {
|
||||
token := &ChainGovernorConfigToken{
|
||||
OriginChainId: t.OriginChainId,
|
||||
OriginAddress: t.OriginAddress,
|
||||
Price: t.Price,
|
||||
}
|
||||
tokens = append(tokens, token)
|
||||
}
|
||||
|
||||
return &ChainGovernorConfigUpdate{
|
||||
NodeName: c.NodeName,
|
||||
Counter: c.Counter,
|
||||
Timestamp: c.Timestamp,
|
||||
Chains: chains,
|
||||
Tokens: tokens,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
|
||||
)
|
||||
|
||||
type Uint64 uint64
|
||||
|
||||
func (u Uint64) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
ui64Str := strconv.FormatUint(uint64(u), 10)
|
||||
d128, err := primitive.ParseDecimal128(ui64Str)
|
||||
return bsontype.Decimal128, bsoncore.AppendDecimal128(nil, d128), err
|
||||
}
|
||||
|
||||
func (u *Uint64) UnmarshalBSONValue(t bsontype.Type, b []byte) error {
|
||||
d128, _, ok := bsoncore.ReadDecimal128(b)
|
||||
if !ok {
|
||||
return errors.New("Uint64 UnmarshalBSONValue error")
|
||||
}
|
||||
|
||||
ui64, err := strconv.ParseUint(d128.String(), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*u = Uint64(ui64)
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue