Skip to content

Commit

Permalink
feat(bpos): add ChangeEIDMinGasPrice proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Aug 14, 2023
1 parent 784bfa2 commit ae204b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
30 changes: 15 additions & 15 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ func GetDefaultParams() *Configuration {
CRAssetsRectifyTransactionHeight: 751400,
ProposalCRVotingPeriod: 7 * 720,
ProposalPublicVotingPeriod: 7 * 720,
VoterRejectPercentage: 10,
MaxCommitteeProposalCount: 128,
MaxCRAssetsAddressUTXOCount: 800,
MinCRAssetsAddressUTXOCount: 720,
RectifyTxFee: 10000,
RealWithdrawSingleFee: 10000,
NewP2PProtocolVersionHeight: 751400,
ChangeCommitteeNewCRHeight: 932530,
CheckVoteCRCountHeight: 658930,
CRClaimPeriod: 720 * 14,
ChangeESCMinGasPriceHeight: math.MaxUint32, // todo complete me
VoterRejectPercentage: 10,
MaxCommitteeProposalCount: 128,
MaxCRAssetsAddressUTXOCount: 800,
MinCRAssetsAddressUTXOCount: 720,
RectifyTxFee: 10000,
RealWithdrawSingleFee: 10000,
NewP2PProtocolVersionHeight: 751400,
ChangeCommitteeNewCRHeight: 932530,
CheckVoteCRCountHeight: 658930,
CRClaimPeriod: 720 * 14,
ChangeSideChainMinGasPriceHeight: 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.ChangeESCMinGasPriceHeight = math.MaxUint32 // todo complete me
p.CRConfiguration.ChangeSideChainMinGasPriceHeight = 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.ChangeESCMinGasPriceHeight = math.MaxUint32 // todo complete me
p.CRConfiguration.ChangeSideChainMinGasPriceHeight = 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"`
// 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"`
// ChangeSideChainMinGasPriceHeight defines the height to use CR proposal to change gas price of side chain
ChangeSideChainMinGasPriceHeight 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
15 changes: 9 additions & 6 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.ChangeESCMinGasPrice:
if blockHeight < chainParams.CRConfiguration.ChangeESCMinGasPriceHeight {
case payload.ChangeESCMinGasPrice, payload.ChangeEIDMinGasPrice:
if blockHeight < chainParams.CRConfiguration.ChangeSideChainMinGasPriceHeight {
return errors.New(fmt.Sprintf("not support %s CRCProposal"+
" transaction before ChangeESCMinGasPriceHeight", p.ProposalType.Name()))
" transaction before ChangeSideChainMinGasPriceHeight", p.ProposalType.Name()))
}
default:
if blockHeight < chainParams.CRConfiguration.CRCommitteeStartHeight {
Expand Down Expand Up @@ -169,8 +169,11 @@ func (t *CRCProposalTransaction) SpecialContextCheck() (result elaerr.ELAError,
if err != nil {
return elaerr.Simple(elaerr.ErrTxPayload, err), true
}
case payload.ChangeESCMinGasPrice:

case payload.ChangeESCMinGasPrice, payload.ChangeEIDMinGasPrice:
err := t.checkChangeSideChainGasPriceProposal(proposal, t.PayloadVersion())
if err != nil {
return elaerr.Simple(elaerr.ErrTxPayload, err), true
}
default:
err := t.checkNormalOrELIPProposal(t.parameters, proposal, t.parameters.ProposalsUsedAmount, t.PayloadVersion())
if err != nil {
Expand Down Expand Up @@ -589,7 +592,7 @@ func (t *CRCProposalTransaction) checkRegisterSideChainProposal(params *Transact
return t.checkOwnerAndCRCouncilMemberSign(proposal, crMember.Info.Code, payloadVersion)
}

func (t *CRCProposalTransaction) checkChangeSideChainFeeProposal(proposal *payload.CRCProposal, payloadVersion byte) error {
func (t *CRCProposalTransaction) checkChangeSideChainGasPriceProposal(proposal *payload.CRCProposal, payloadVersion byte) error {
_, err := crypto.DecodePoint(proposal.OwnerKey)
if err != nil {
return errors.New("DecodePoint from OwnerKey error")
Expand Down
19 changes: 11 additions & 8 deletions core/types/payload/crcproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
// 0x06 Change side chain transaction fee
// change ESC side chain min gas price
ChangeESCMinGasPrice CRCProposalType = 0x0600
ChangeEIDMinGasPrice CRCProposalType = 0x0601
)

type CRCProposalType uint16
Expand Down Expand Up @@ -97,6 +98,8 @@ func (pt CRCProposalType) Name() string {
return "ChangeCustomIDFee"
case ChangeESCMinGasPrice:
return "ChangeESCMinGasPrice"
case ChangeEIDMinGasPrice:
return "ChangeEIDMinGasPrice"
default:
return "Unknown"
}
Expand Down Expand Up @@ -182,7 +185,7 @@ type CRCProposal struct {

CustomIDFeeRateInfo

ChangeESCMinGasPriceInfo
ChangeSideChainMinGasPriceInfo

// The specified ELA address where the funds are to be sent.
NewRecipient common.Uint168
Expand Down Expand Up @@ -399,15 +402,15 @@ func (sc *CustomIDFeeRateInfo) Deserialize(r io.Reader) error {
return nil
}

type ChangeESCMinGasPriceInfo struct {
type ChangeSideChainMinGasPriceInfo 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 {
func (sc *ChangeSideChainMinGasPriceInfo) Serialize(w io.Writer) error {
if err := sc.MinGasPrice.Serialize(w); err != nil {
return errors.New("failed to serialize MinGasPrice")
}
Expand All @@ -419,7 +422,7 @@ func (sc *ChangeESCMinGasPriceInfo) Serialize(w io.Writer) error {
return nil
}

func (sc *ChangeESCMinGasPriceInfo) Deserialize(r io.Reader) error {
func (sc *ChangeSideChainMinGasPriceInfo) Deserialize(r io.Reader) error {
var err error
if err = sc.MinGasPrice.Deserialize(r); err != nil {
return errors.New("failed to deserialize MinGasPrice")
Expand Down Expand Up @@ -459,7 +462,7 @@ func (p *CRCProposal) SerializeUnsigned(w io.Writer, version byte) error {
return p.SerializeUnsignedChangeCustomIDFee(w, version)
case RegisterSideChain:
return p.SerializeUnsignedRegisterSideChain(w, version)
case ChangeESCMinGasPrice:
case ChangeESCMinGasPrice, ChangeEIDMinGasPrice:
return p.SerializeChangeSideChainFee(w, version)
default:
return p.SerializeUnsignedNormalOrELIP(w, version)
Expand Down Expand Up @@ -648,7 +651,7 @@ func (p *CRCProposal) SerializeChangeSideChainFee(w io.Writer, version byte) err
}
}

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

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

if err = p.ChangeESCMinGasPriceInfo.Deserialize(r); err != nil {
if err = p.ChangeSideChainMinGasPriceInfo.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.ChangeESCMinGasPrice:
case payload.ChangeESCMinGasPrice, payload.ChangeEIDMinGasPrice:
needRecordResult = true

default:
Expand Down

0 comments on commit ae204b5

Please sign in to comment.