Skip to content

Commit

Permalink
feat(bpos): add check and process logic for ChangeESCMinGasPrice prop…
Browse files Browse the repository at this point in the history
…osal
  • Loading branch information
RainFallsSilent committed Aug 14, 2023
1 parent f9f719f commit 784bfa2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
10 changes: 5 additions & 5 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func GetDefaultParams() *Configuration {
ChangeCommitteeNewCRHeight: 932530,
CheckVoteCRCountHeight: 658930,
CRClaimPeriod: 720 * 14,
ChangeSideChainFeeHeight: math.MaxUint32, // todo complete me
ChangeESCMinGasPriceHeight: math.MaxUint32, // todo complete me
},

DPoSConfiguration: DPoSConfiguration{
Expand Down Expand Up @@ -400,7 +400,7 @@ func (p *Configuration) TestNet() *Configuration {

p.MemoryPoolTxMaximumStayHeight = 10

p.CRConfiguration.ChangeSideChainFeeHeight = math.MaxUint32 // todo complete me
p.CRConfiguration.ChangeESCMinGasPriceHeight = math.MaxUint32 // todo complete me

return p
}
Expand Down Expand Up @@ -523,7 +523,7 @@ func (p *Configuration) RegNet() *Configuration {
p.MultiExchangeVotesStartHeight = math.MaxUint32 // todo complete me
p.DPoSConfiguration.DexStartHeight = math.MaxUint32 // todo complete me

p.CRConfiguration.ChangeSideChainFeeHeight = math.MaxUint32 // todo complete me
p.CRConfiguration.ChangeESCMinGasPriceHeight = math.MaxUint32 // todo complete me

p.MemoryPoolTxMaximumStayHeight = 10

Expand Down Expand Up @@ -815,8 +815,8 @@ type CRConfiguration struct {
CRCProposalDraftDataStartHeight uint32 `screw:"--crcproposaldraftdatastartheight" usage:"defines the proposal draft data start height"`
// CRClaimPeriod defines the duration of CR claim DPoS node period which measured by block height
CRClaimPeriod uint32 `screw:"--crclaimperiod" usage:"defines the duration of CR claim DPoS node"`
// ChangeSideChainFeeHeight defines the height to use CR proposal to change gas price of side chain
ChangeSideChainFeeHeight uint32 `screw:"--changesidechainfeeheight" usage:"defines the height to use CR proposal to change gas price of side chain"`
// ChangeESCMinGasPriceHeight defines the height to use CR proposal to change gas price of side chain
ChangeESCMinGasPriceHeight uint32 `screw:"--changesidechainfeeheight" usage:"defines the height to use CR proposal to change gas price of side chain"`
}

// PowConfiguration defines the Proof-of-Work parameters.
Expand Down
10 changes: 5 additions & 5 deletions core/transaction/crcproposaltransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (t *CRCProposalTransaction) HeightVersionCheck() error {
return errors.New(fmt.Sprintf("not support %s CRCProposal"+
" transaction before NewCrossChainStartHeight", p.ProposalType.Name()))
}
case payload.SetESCMinGasPrice:
if blockHeight < chainParams.CRConfiguration.ChangeSideChainFeeHeight {
case payload.ChangeESCMinGasPrice:
if blockHeight < chainParams.CRConfiguration.ChangeESCMinGasPriceHeight {
return errors.New(fmt.Sprintf("not support %s CRCProposal"+
" transaction before ChangeSideChainFeeHeight", p.ProposalType.Name()))
" transaction before ChangeESCMinGasPriceHeight", p.ProposalType.Name()))
}
default:
if blockHeight < chainParams.CRConfiguration.CRCommitteeStartHeight {
Expand Down Expand Up @@ -169,7 +169,7 @@ func (t *CRCProposalTransaction) SpecialContextCheck() (result elaerr.ELAError,
if err != nil {
return elaerr.Simple(elaerr.ErrTxPayload, err), true
}
case payload.SetESCMinGasPrice:
case payload.ChangeESCMinGasPrice:

default:
err := t.checkNormalOrELIPProposal(t.parameters, proposal, t.parameters.ProposalsUsedAmount, t.PayloadVersion())
Expand Down Expand Up @@ -566,7 +566,7 @@ func (t *CRCProposalTransaction) checkRegisterSideChainProposal(params *Transact
return errors.New("ExchangeRate should be 1.0")
}

if proposal.EffectiveHeight < t.parameters.BlockChain.GetHeight() {
if proposal.SideChainInfo.EffectiveHeight < t.parameters.BlockChain.GetHeight() {
return errors.New("EffectiveHeight must be bigger than current height")
}

Expand Down
51 changes: 42 additions & 9 deletions core/types/payload/crcproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const (

// 0x06 Change side chain transaction fee
// change ESC side chain min gas price
SetESCMinGasPrice CRCProposalType = 0x0600
ChangeESCMinGasPrice CRCProposalType = 0x0600
)

type CRCProposalType uint16
Expand Down Expand Up @@ -95,8 +95,8 @@ func (pt CRCProposalType) Name() string {
return "ReceiveCustomID"
case ChangeCustomIDFee:
return "ChangeCustomIDFee"
case SetESCMinGasPrice:
return "SetESCMinGasPrice"
case ChangeESCMinGasPrice:
return "ChangeESCMinGasPrice"
default:
return "Unknown"
}
Expand Down Expand Up @@ -182,6 +182,8 @@ type CRCProposal struct {

CustomIDFeeRateInfo

ChangeESCMinGasPriceInfo

// The specified ELA address where the funds are to be sent.
NewRecipient common.Uint168

Expand Down Expand Up @@ -216,8 +218,6 @@ type CRCProposal struct {
// The registered side chain information
SideChainInfo

MinGasPrice common.Fixed64

hash *common.Uint256
}

Expand Down Expand Up @@ -399,6 +399,39 @@ func (sc *CustomIDFeeRateInfo) Deserialize(r io.Reader) error {
return nil
}

type ChangeESCMinGasPriceInfo struct {
// The min gas price of ESC side chain
MinGasPrice common.Fixed64

// Effective at the side chain height of ESC.
EffectiveHeight uint32
}

func (sc *ChangeESCMinGasPriceInfo) Serialize(w io.Writer) error {
if err := sc.MinGasPrice.Serialize(w); err != nil {
return errors.New("failed to serialize MinGasPrice")
}

if err := common.WriteUint32(w, sc.EffectiveHeight); err != nil {
return errors.New("failed to serialize EffectiveHeight")
}

return nil
}

func (sc *ChangeESCMinGasPriceInfo) Deserialize(r io.Reader) error {
var err error
if err = sc.MinGasPrice.Deserialize(r); err != nil {
return errors.New("failed to deserialize MinGasPrice")
}

sc.EffectiveHeight, err = common.ReadUint32(r)
if err != nil {
return errors.New("failed to deserialize EffectiveHeight")
}
return nil
}

func (p *CRCProposal) Data(version byte) []byte {
buf := new(bytes.Buffer)
if err := p.SerializeUnsigned(buf, version); err != nil {
Expand Down Expand Up @@ -426,7 +459,7 @@ func (p *CRCProposal) SerializeUnsigned(w io.Writer, version byte) error {
return p.SerializeUnsignedChangeCustomIDFee(w, version)
case RegisterSideChain:
return p.SerializeUnsignedRegisterSideChain(w, version)
case SetESCMinGasPrice:
case ChangeESCMinGasPrice:
return p.SerializeChangeSideChainFee(w, version)
default:
return p.SerializeUnsignedNormalOrELIP(w, version)
Expand Down Expand Up @@ -615,7 +648,7 @@ func (p *CRCProposal) SerializeChangeSideChainFee(w io.Writer, version byte) err
}
}

if err := p.MinGasPrice.Serialize(w); err != nil {
if err := p.ChangeESCMinGasPriceInfo.Serialize(w); err != nil {
return err
}

Expand Down Expand Up @@ -912,7 +945,7 @@ func (p *CRCProposal) DeserializeUnSigned(r io.Reader, version byte) error {
return p.DeserializeUnSignedChangeCustomIDFee(r, version)
case RegisterSideChain:
return p.DeserializeUnsignedRegisterSideChain(r, version)
case SetESCMinGasPrice:
case ChangeESCMinGasPrice:
return p.DeserializeChangeSideChainFee(r, version)
default:
return p.DeserializeUnSignedNormalOrELIP(r, version)
Expand Down Expand Up @@ -1064,7 +1097,7 @@ func (p *CRCProposal) DeserializeChangeSideChainFee(r io.Reader, version byte) e
}
}

if err = p.MinGasPrice.Deserialize(r); err != nil {
if err = p.ChangeESCMinGasPriceInfo.Deserialize(r); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cr/state/proposalmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func recordPartProposalResult(results *[]payload.ProposalResult,
case payload.ReserveCustomID, payload.ReceiveCustomID, payload.ChangeCustomIDFee:
needRecordResult = true

case payload.SetESCMinGasPrice:
case payload.ChangeESCMinGasPrice:
needRecordResult = true

default:
Expand Down
2 changes: 1 addition & 1 deletion servers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3479,7 +3479,7 @@ func getPayloadInfo(tx interfaces.Transaction, payloadVersion byte) PayloadInfo
obj.MagicNumber = object.MagicNumber
obj.GenesisHash = common.ToReversedString(object.GenesisHash)
obj.ExchangeRate = object.ExchangeRate
obj.EffectiveHeight = object.EffectiveHeight
obj.EffectiveHeight = object.SideChainInfo.EffectiveHeight
obj.ResourcePath = object.ResourcePath
obj.Signature = common.BytesToHexString(object.Signature)
crmdid, _ := object.CRCouncilMemberDID.ToAddress()
Expand Down

0 comments on commit 784bfa2

Please sign in to comment.