diff --git a/consensus/misc/rewards.go b/consensus/misc/rewards.go index e0bc11b026..7bad9c4b66 100644 --- a/consensus/misc/rewards.go +++ b/consensus/misc/rewards.go @@ -36,6 +36,11 @@ func CalculateQiReward(header *types.WorkObjectHeader) *big.Int { return big.NewInt(1000) } +// CalculateExchangeRate based on the quai to qi and qi to quai exchange rates +func CalculateExchangeRate(quaiToQi *big.Int, qiToQuai *big.Int) *big.Int { + return new(big.Int).Div(quaiToQi, qiToQuai) +} + // FindMinDenominations finds the minimum number of denominations to make up the reward func FindMinDenominations(reward *big.Int) map[uint8]uint64 { // Store the count of each denomination used (map denomination to count) diff --git a/core/genesis.go b/core/genesis.go index a40e0a0145..9cc61ad5fb 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -293,6 +293,10 @@ func (g *Genesis) ToBlock(startingExpansionNumber uint64) *types.WorkObject { wo.Header().SetStateUsed(0) wo.Header().SetEtxSetRoot(types.EmptyRootHash) wo.Header().SetSecondaryCoinbase(common.Zero) + wo.Header().SetExchangeRate(params.ExchangeRate) + wo.Header().SetQuaiToQi(params.QuaiToQiConversionBase) + wo.Header().SetQiToQuai(params.QiToQuaiConversionBase) + if g.GasLimit == 0 { wo.Header().SetGasLimit(params.GenesisGasLimit) } diff --git a/core/slice.go b/core/slice.go index e358344227..a791007a1d 100644 --- a/core/slice.go +++ b/core/slice.go @@ -457,7 +457,7 @@ func (sl *Slice) asyncPendingHeaderLoop() { case asyncPh := <-sl.asyncPhCh: sl.hc.headermu.Lock() bestPh := sl.ReadBestPh() - if bestPh.ParentHash(common.ZONE_CTX) == asyncPh.ParentHash(common.ZONE_CTX) { + if asyncPh != nil && bestPh != nil && bestPh.ParentHash(common.ZONE_CTX) == asyncPh.ParentHash(common.ZONE_CTX) { combinedPendingHeader := sl.combinePendingHeader(asyncPh, bestPh, common.ZONE_CTX, true) sl.SetBestPh(combinedPendingHeader) } @@ -898,6 +898,9 @@ func (sl *Slice) combinePendingHeader(header *types.WorkObject, slPendingHeader combinedPendingHeader.Header().SetExpansionNumber(header.ExpansionNumber()) combinedPendingHeader.Header().SetEtxEligibleSlices(header.EtxEligibleSlices()) combinedPendingHeader.Header().SetInterlinkRootHash(header.InterlinkRootHash()) + combinedPendingHeader.Header().SetExchangeRate(header.ExchangeRate()) + combinedPendingHeader.Header().SetQiToQuai(header.QiToQuai()) + combinedPendingHeader.Header().SetQuaiToQi(header.QuaiToQi()) } if inSlice { diff --git a/core/types/block.go b/core/types/block.go index 61f16a65e9..40c1cb7b37 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -115,6 +115,9 @@ type Header struct { stateLimit uint64 `json:"stateLimit" gencodec:"required"` stateUsed uint64 `json:"stateUsed" gencodec:"required"` secondaryCoinbase common.Address `json:secondaryCoinbase gencodec:"required"` + exchangeRate *big.Int `json:"exchangeRate" gencodec:"required"` + quaiToQi *big.Int `json:"quaiToQi" gencodec:"required"` + qiToQuai *big.Int `json:"qiToQuai" gencodec:"required"` // caches hash atomic.Value @@ -150,6 +153,9 @@ func EmptyHeader() *Header { h.primeTerminusHash = EmptyRootHash h.interlinkRootHash = EmptyRootHash h.secondaryCoinbase = common.Address{} + h.exchangeRate = big.NewInt(0) + h.quaiToQi = big.NewInt(0) + h.qiToQuai = big.NewInt(0) for i := 0; i < common.HierarchyDepth; i++ { h.manifestHash[i] = EmptyRootHash @@ -219,6 +225,9 @@ func (h *Header) ProtoEncode() (*ProtoHeader, error) { efficiencyScore := uint64(h.EfficiencyScore()) thresholdCount := uint64(h.ThresholdCount()) expansionNumber := uint64(h.ExpansionNumber()) + exchangeRate := h.exchangeRate.Bytes() + quaiToQi := h.quaiToQi.Bytes() + qiToQuai := h.qiToQuai.Bytes() protoHeader := &ProtoHeader{ UncleHash: &uncleHash, @@ -244,6 +253,9 @@ func (h *Header) ProtoEncode() (*ProtoHeader, error) { StateLimit: &stateLimit, StateUsed: &stateUsed, Extra: h.Extra(), + ExchangeRate: exchangeRate, + QuaiToQi: quaiToQi, + QiToQuai: qiToQuai, } for i := 0; i < common.HierarchyDepth; i++ { @@ -342,6 +354,15 @@ func (h *Header) ProtoDecode(protoHeader *ProtoHeader, location common.Location) if protoHeader.SecondaryCoinbase == nil { return errors.New("missing required field 'secondaryCoinbase' in Header") } + if protoHeader.ExchangeRate == nil { + return errors.New("missing required field 'ExchangeRate' in Header") + } + if protoHeader.QuaiToQi == nil { + return errors.New("missing required field 'QuaiToQi' in Header") + } + if protoHeader.QiToQuai == nil { + return errors.New("missing required field 'QiToQuai' in Header") + } // Initialize the array fields before setting h.parentHash = make([]common.Hash, common.HierarchyDepth-1) @@ -385,6 +406,9 @@ func (h *Header) ProtoDecode(protoHeader *ProtoHeader, location common.Location) h.SetExpansionNumber(uint8(protoHeader.GetExpansionNumber())) h.SetEtxEligibleSlices(common.BytesToHash(protoHeader.GetEtxEligibleSlices().GetValue())) h.SetSecondaryCoinbase(common.BytesToAddress(protoHeader.GetSecondaryCoinbase(), location)) + h.SetExchangeRate(new(big.Int).SetBytes(protoHeader.GetExchangeRate())) + h.SetQuaiToQi(new(big.Int).SetBytes(protoHeader.GetQuaiToQi())) + h.SetQiToQuai(new(big.Int).SetBytes(protoHeader.GetQiToQuai())) return nil } @@ -424,6 +448,9 @@ func (h *Header) RPCMarshalHeader() map[string]interface{} { "stateLimit": hexutil.Uint64(h.StateLimit()), "stateUsed": hexutil.Uint64(h.StateUsed()), "secondaryCoinbase": h.SecondaryCoinbase().Hex(), + "exchangeRate": (*hexutil.Big)(h.ExchangeRate()), + "quaiToQi": (*hexutil.Big)(h.QuaiToQi()), + "qiToQuai": (*hexutil.Big)(h.QiToQuai()), } number := make([]*hexutil.Big, common.HierarchyDepth-1) @@ -536,6 +563,9 @@ func (h *Header) InterlinkRootHash() common.Hash { return h.interlinkRootHash } func (h *Header) SecondaryCoinbase() common.Address { return h.secondaryCoinbase } +func (h *Header) ExchangeRate() *big.Int { return h.exchangeRate } +func (h *Header) QuaiToQi() *big.Int { return h.quaiToQi } +func (h *Header) QiToQuai() *big.Int { return h.qiToQuai } func (h *Header) SetParentHash(val common.Hash, nodeCtx int) { h.hash = atomic.Value{} // clear hash cache @@ -688,6 +718,24 @@ func (h *Header) SetSecondaryCoinbase(val common.Address) { h.secondaryCoinbase = val } +func (h *Header) SetExchangeRate(val *big.Int) { + h.hash = atomic.Value{} + h.sealHash = atomic.Value{} + h.exchangeRate = new(big.Int).Set(val) +} + +func (h *Header) SetQuaiToQi(val *big.Int) { + h.hash = atomic.Value{} + h.sealHash = atomic.Value{} + h.quaiToQi = new(big.Int).Set(val) +} + +func (h *Header) SetQiToQuai(val *big.Int) { + h.hash = atomic.Value{} + h.sealHash = atomic.Value{} + h.qiToQuai = new(big.Int).Set(val) +} + // Array accessors func (h *Header) ParentHashArray() []common.Hash { return h.parentHash } func (h *Header) ManifestHashArray() []common.Hash { return h.manifestHash } @@ -716,6 +764,9 @@ func (h *Header) SealEncode() *ProtoHeader { gasUsed := h.GasUsed() stateLimit := h.StateLimit() stateUsed := h.StateUsed() + exchangeRate := h.exchangeRate.Bytes() + quaiToQi := h.quaiToQi.Bytes() + qiToQuai := h.qiToQuai.Bytes() protoSealData := &ProtoHeader{ UncleHash: &uncleHash, @@ -741,6 +792,9 @@ func (h *Header) SealEncode() *ProtoHeader { ExpansionNumber: &expansionNumber, Extra: h.Extra(), SecondaryCoinbase: h.SecondaryCoinbase().Bytes(), + ExchangeRate: exchangeRate, + QuaiToQi: quaiToQi, + QiToQuai: qiToQuai, } for i := 0; i < common.HierarchyDepth; i++ { @@ -925,6 +979,9 @@ func CopyHeader(h *Header) *Header { cpy.SetBaseFee(h.BaseFee()) cpy.SetStateLimit(h.StateLimit()) cpy.SetStateUsed(h.StateUsed()) + cpy.SetExchangeRate(h.ExchangeRate()) + cpy.SetQuaiToQi(h.QuaiToQi()) + cpy.SetQiToQuai(h.QiToQuai()) return &cpy } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 9ff95b96c6..06ca04f8aa 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -43,6 +43,9 @@ func (h Header) MarshalJSON() ([]byte, error) { StateUsed hexutil.Uint64 `json:"stateUsed" gencodec:"required"` Extra hexutil.Bytes `json:"extraData" gencodec:"required"` SecondaryCoinbase string `json:"secondaryCoinbase" gencodec:"required"` + ExchangeRate *hexutil.Big `json:"exchangeRate" gencodec:"required"` + QuaiToQi *hexutil.Big `json:"quaiToQi" gencodec:"required"` + QiToQuai *hexutil.Big `json:"qiToQuai" gencodec:"required"` } // Initialize the enc struct enc.ParentEntropy = make([]*hexutil.Big, common.HierarchyDepth) @@ -84,6 +87,9 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.StateUsed = hexutil.Uint64(h.StateUsed()) enc.Extra = hexutil.Bytes(h.Extra()) enc.SecondaryCoinbase = h.SecondaryCoinbase().Hex() + enc.ExchangeRate = (*hexutil.Big)(h.ExchangeRate()) + enc.QuaiToQi = (*hexutil.Big)(h.QuaiToQi()) + enc.QiToQuai = (*hexutil.Big)(h.QiToQuai()) raw, err := json.Marshal(&enc) return raw, err } @@ -120,6 +126,9 @@ func (h *Header) UnmarshalJSON(input []byte) error { StateUsed *hexutil.Uint64 `json:"stateUsed" gencodec:"required"` Extra hexutil.Bytes `json:"extraData" gencodec:"required"` SecondaryCoinbase string `json:"secondaryCoinbase" gencodec:"required"` + ExchangeRate *hexutil.Big `json:"exchangeRate" gencodec:"required"` + QuaiToQi *hexutil.Big `json:"quaiToQi" gencodec:"required"` + QiToQuai *hexutil.Big `json:"qiToQuai" gencodec:"required"` } if err := json.Unmarshal(input, &dec); err != nil { return err @@ -208,6 +217,15 @@ func (h *Header) UnmarshalJSON(input []byte) error { if len(dec.SecondaryCoinbase) == 0 { return errors.New("missing required field 'secondaryCoinbase' for Header") } + if dec.ExchangeRate == nil { + return errors.New("missing required field 'exchangeRate' for Header") + } + if dec.QuaiToQi == nil { + return errors.New("missing required field 'quaiToQi' for Header") + } + if dec.QiToQuai == nil { + return errors.New("missing required field 'qiToQuai' for Header") + } // Initialize the header h.parentHash = make([]common.Hash, common.HierarchyDepth-1) h.manifestHash = make([]common.Hash, common.HierarchyDepth) @@ -267,6 +285,9 @@ func (h *Header) UnmarshalJSON(input []byte) error { return err } h.SetSecondaryCoinbase(coinbaseAddr.Address()) + h.SetExchangeRate((*big.Int)(dec.ExchangeRate)) + h.SetQuaiToQi((*big.Int)(dec.QuaiToQi)) + h.SetQiToQuai((*big.Int)(dec.QiToQuai)) return nil } diff --git a/core/types/proto_block.pb.go b/core/types/proto_block.pb.go index 7e371e64c1..0cc3d79c56 100644 --- a/core/types/proto_block.pb.go +++ b/core/types/proto_block.pb.go @@ -59,6 +59,9 @@ type ProtoHeader struct { StateUsed *uint64 `protobuf:"varint,31,opt,name=state_used,json=stateUsed,proto3,oneof" json:"state_used,omitempty"` QuaiStateSize []byte `protobuf:"bytes,32,opt,name=quai_state_size,json=quaiStateSize,proto3,oneof" json:"quai_state_size,omitempty"` SecondaryCoinbase []byte `protobuf:"bytes,33,opt,name=secondary_coinbase,json=secondaryCoinbase,proto3,oneof" json:"secondary_coinbase,omitempty"` + ExchangeRate []byte `protobuf:"bytes,34,opt,name=exchange_rate,json=exchangeRate,proto3,oneof" json:"exchange_rate,omitempty"` + QuaiToQi []byte `protobuf:"bytes,35,opt,name=quai_to_qi,json=quaiToQi,proto3,oneof" json:"quai_to_qi,omitempty"` + QiToQuai []byte `protobuf:"bytes,36,opt,name=qi_to_quai,json=qiToQuai,proto3,oneof" json:"qi_to_quai,omitempty"` } func (x *ProtoHeader) Reset() { @@ -324,6 +327,27 @@ func (x *ProtoHeader) GetSecondaryCoinbase() []byte { return nil } +func (x *ProtoHeader) GetExchangeRate() []byte { + if x != nil { + return x.ExchangeRate + } + return nil +} + +func (x *ProtoHeader) GetQuaiToQi() []byte { + if x != nil { + return x.QuaiToQi + } + return nil +} + +func (x *ProtoHeader) GetQiToQuai() []byte { + if x != nil { + return x.QiToQuai + } + return nil +} + type ProtoTransaction struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2456,7 +2480,7 @@ var file_core_types_proto_block_proto_rawDesc = []byte{ 0x74, 0x6f, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x1a, 0x19, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0xa1, 0x10, 0x0a, 0x0b, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, + 0x22, 0xc1, 0x11, 0x0a, 0x0b, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x32, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x48, 0x61, 0x73, 0x68, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, @@ -2557,7 +2581,14 @@ var file_core_types_proto_block_proto_rawDesc = []byte{ 0x69, 0x7a, 0x65, 0x88, 0x01, 0x01, 0x12, 0x32, 0x0a, 0x12, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x62, 0x61, 0x73, 0x65, 0x18, 0x21, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x1a, 0x52, 0x11, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x43, - 0x6f, 0x69, 0x6e, 0x62, 0x61, 0x73, 0x65, 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x75, + 0x6f, 0x69, 0x6e, 0x62, 0x61, 0x73, 0x65, 0x88, 0x01, 0x01, 0x12, 0x28, 0x0a, 0x0d, 0x65, 0x78, + 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x18, 0x22, 0x20, 0x01, 0x28, + 0x0c, 0x48, 0x1b, 0x52, 0x0c, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x61, 0x74, + 0x65, 0x88, 0x01, 0x01, 0x12, 0x21, 0x0a, 0x0a, 0x71, 0x75, 0x61, 0x69, 0x5f, 0x74, 0x6f, 0x5f, + 0x71, 0x69, 0x18, 0x23, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x1c, 0x52, 0x08, 0x71, 0x75, 0x61, 0x69, + 0x54, 0x6f, 0x51, 0x69, 0x88, 0x01, 0x01, 0x12, 0x21, 0x0a, 0x0a, 0x71, 0x69, 0x5f, 0x74, 0x6f, + 0x5f, 0x71, 0x75, 0x61, 0x69, 0x18, 0x24, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x1d, 0x52, 0x08, 0x71, + 0x69, 0x54, 0x6f, 0x51, 0x75, 0x61, 0x69, 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x75, 0x6e, 0x63, 0x6c, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x65, 0x76, 0x6d, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x74, 0x78, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x42, 0x14, 0x0a, 0x12, 0x5f, 0x6f, 0x75, 0x74, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x5f, @@ -2586,7 +2617,10 @@ var file_core_types_proto_block_proto_rawDesc = []byte{ 0x74, 0x61, 0x74, 0x65, 0x5f, 0x75, 0x73, 0x65, 0x64, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x71, 0x75, 0x61, 0x69, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x15, 0x0a, 0x13, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x5f, 0x63, 0x6f, 0x69, 0x6e, - 0x62, 0x61, 0x73, 0x65, 0x22, 0xd6, 0x08, 0x0a, 0x10, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x72, + 0x62, 0x61, 0x73, 0x65, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x71, 0x75, 0x61, 0x69, 0x5f, + 0x74, 0x6f, 0x5f, 0x71, 0x69, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x71, 0x69, 0x5f, 0x74, 0x6f, 0x5f, + 0x71, 0x75, 0x61, 0x69, 0x22, 0xd6, 0x08, 0x0a, 0x10, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x88, 0x01, 0x01, 0x12, 0x13, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x01, diff --git a/core/types/proto_block.proto b/core/types/proto_block.proto index 3d5553a5e4..fdf662a9d3 100644 --- a/core/types/proto_block.proto +++ b/core/types/proto_block.proto @@ -39,6 +39,9 @@ message ProtoHeader { optional uint64 state_used = 31; optional bytes quai_state_size = 32; optional bytes secondary_coinbase = 33; + optional bytes exchange_rate = 34; + optional bytes quai_to_qi = 35; + optional bytes qi_to_quai = 36; } message ProtoTransaction { diff --git a/core/types/wo.go b/core/types/wo.go index 2f8ef5c6d3..ad863d2e6d 100644 --- a/core/types/wo.go +++ b/core/types/wo.go @@ -404,6 +404,18 @@ func (wo *WorkObject) InterlinkHashes() common.Hashes { return wo.Body().InterlinkHashes() } +func (wo *WorkObject) ExchangeRate() *big.Int { + return wo.Header().ExchangeRate() +} + +func (wo *WorkObject) QuaiToQi() *big.Int { + return wo.Header().QuaiToQi() +} + +func (wo *WorkObject) QiToQuai() *big.Int { + return wo.Header().QiToQuai() +} + func (wo *WorkObject) QiTransactions() []*Transaction { qiTxs := make([]*Transaction, 0) for _, t := range wo.Transactions() { diff --git a/core/worker.go b/core/worker.go index 0eca15f8ea..86a3849b11 100644 --- a/core/worker.go +++ b/core/worker.go @@ -1478,6 +1478,45 @@ func (w *worker) prepareWork(genParams *generateParams, wo *types.WorkObject) (* newWo.Header().SetInterlinkRootHash(interlinkRootHash) } + // Calculate the new Qi/Quai exchange rate + if nodeCtx == common.PRIME_CTX { + var subRollup types.Transactions + rollup, exists := w.hc.subRollupCache.Peek(parent.Hash()) + if exists && rollup != nil { + subRollup = rollup + w.logger.WithFields(log.Fields{ + "Hash": parent.Hash(), + "len": len(subRollup), + }).Debug("Found the rollup in cache") + } else { + subRollup, err = w.hc.CollectSubRollup(parent) + if err != nil { + return nil, err + } + w.hc.subRollupCache.Add(parent.Hash(), subRollup) + } + qiToQuai := new(big.Int).Set(common.Big0) + quaiToQi := new(big.Int).Set(common.Big0) + for _, tx := range subRollup { + if types.IsCoinBaseTx(tx) { + if tx.ETXSender().IsInQiLedgerScope() { + qiToQuai = new(big.Int).Add(qiToQuai, tx.Value()) + } else if tx.ETXSender().IsInQuaiLedgerScope() { + quaiToQi = new(big.Int).Add(quaiToQi, tx.Value()) + } + } else if types.IsConversionTx(tx) { + if tx.To().IsInQiLedgerScope() { + quaiToQi = new(big.Int).Add(quaiToQi, tx.Value()) + } else if tx.To().IsInQuaiLedgerScope() { + qiToQuai = new(big.Int).Add(qiToQuai, tx.Value()) + } + } + } + newWo.Header().SetQiToQuai(qiToQuai) + newWo.Header().SetQuaiToQi(quaiToQi) + newWo.Header().SetExchangeRate(params.ExchangeRate) + } + // Only zone should calculate state if nodeCtx == common.ZONE_CTX && w.hc.ProcessingState() { newWo.Header().SetExtra(w.extra) diff --git a/go.mod b/go.mod index 5d987a2383..311e902028 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,6 @@ require ( require ( github.com/DataDog/zstd v1.4.5 // indirect - github.com/Jorropo/jsync v1.0.1 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect diff --git a/go.sum b/go.sum index e44f068c00..d2357d780d 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,6 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM= -github.com/Jorropo/jsync v1.0.1 h1:6HgRolFZnsdfzRUj+ImB9og1JYOxQoReSywkHOGSaUU= -github.com/Jorropo/jsync v1.0.1/go.mod h1:jCOZj3vrBCri3bSU3ErUYvevKlnbssrXeCivybS5ABQ= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI= diff --git a/params/protocol_params.go b/params/protocol_params.go index 3e405407af..46ae05ae85 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -181,6 +181,11 @@ var ( WorkSharesInclusionDepth = 3 // Number of blocks upto which the work shares can be referenced and this is protocol enforced LockupByteToBlockDepth = make(map[uint8]uint64) LockupByteToRewardsRatio = make(map[uint8]*big.Int) + + ExchangeRate = big.NewInt(1000000000000000) // This is the initial exchange rate in Qi per Quai in Its/Qit + // These numbers should be "equivalent" to the initial conversion rate + QuaiToQiConversionBase = big.NewInt(10000000) // Is the starting "historical conversion" in Qits for 10,000 Quai we need 10,000*1e3 + QiToQuaiConversionBase = big.NewInt(10000000) // Is the starting "historical conversion" in Qits for 10,000 Qi we need 10,000*1e3 ) func init() {