Skip to content

Commit

Permalink
feat(bpos): change proposal type to ChangeSideChainMinGasPrice
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Aug 15, 2023
1 parent df9a01a commit 568ef32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/transaction/crcproposaltransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (t *CRCProposalTransaction) HeightVersionCheck() error {
return errors.New(fmt.Sprintf("not support %s CRCProposal"+
" transaction before NewCrossChainStartHeight", p.ProposalType.Name()))
}
case payload.ChangeESCMinGasPrice, payload.ChangeEIDMinGasPrice:
case payload.ChangeSideChainMinGasPrice:
if blockHeight < chainParams.CRConfiguration.ChangeSideChainMinGasPriceHeight {
return errors.New(fmt.Sprintf("not support %s CRCProposal"+
" transaction before ChangeSideChainMinGasPriceHeight", p.ProposalType.Name()))
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.ChangeESCMinGasPrice, payload.ChangeEIDMinGasPrice:
case payload.ChangeSideChainMinGasPrice:
err := t.checkChangeSideChainGasPriceProposal(proposal, t.PayloadVersion())
if err != nil {
return elaerr.Simple(elaerr.ErrTxPayload, err), true
Expand Down
28 changes: 17 additions & 11 deletions core/types/payload/crcproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ const (
ReceiveCustomID CRCProposalType = 0x0501
// The rate of custom id fee.
ChangeCustomIDFee CRCProposalType = 0x0502

// 0x06 Change side chain transaction fee
// change ESC side chain min gas price
ChangeESCMinGasPrice CRCProposalType = 0x0600
ChangeEIDMinGasPrice CRCProposalType = 0x0601
// change side chain min gas price
ChangeSideChainMinGasPrice CRCProposalType = 0x0503
)

type CRCProposalType uint16
Expand Down Expand Up @@ -96,10 +93,8 @@ func (pt CRCProposalType) Name() string {
return "ReceiveCustomID"
case ChangeCustomIDFee:
return "ChangeCustomIDFee"
case ChangeESCMinGasPrice:
return "ChangeESCMinGasPrice"
case ChangeEIDMinGasPrice:
return "ChangeEIDMinGasPrice"
case ChangeSideChainMinGasPrice:
return "ChangeSideChainMinGasPrice"
default:
return "Unknown"
}
Expand Down Expand Up @@ -403,6 +398,9 @@ func (sc *CustomIDFeeRateInfo) Deserialize(r io.Reader) error {
}

type ChangeSideChainMinGasPriceInfo struct {
// Genesis hash of side chain
GenesisBlockHash common.Uint256

// The min gas price of ESC side chain
MinGasPrice common.Fixed64

Expand All @@ -411,6 +409,10 @@ type ChangeSideChainMinGasPriceInfo struct {
}

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

if err := sc.MinGasPrice.Serialize(w); err != nil {
return errors.New("failed to serialize MinGasPrice")
}
Expand All @@ -424,6 +426,10 @@ func (sc *ChangeSideChainMinGasPriceInfo) Serialize(w io.Writer) error {

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

if err = sc.MinGasPrice.Deserialize(r); err != nil {
return errors.New("failed to deserialize MinGasPrice")
}
Expand Down Expand Up @@ -462,7 +468,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, ChangeEIDMinGasPrice:
case ChangeSideChainMinGasPrice:
return p.SerializeChangeSideChainFee(w, version)
default:
return p.SerializeUnsignedNormalOrELIP(w, version)
Expand Down Expand Up @@ -948,7 +954,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, ChangeEIDMinGasPrice:
case ChangeSideChainMinGasPrice:
return p.DeserializeChangeSideChainFee(r, version)
default:
return p.DeserializeUnSignedNormalOrELIP(r, version)
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, payload.ChangeEIDMinGasPrice:
case payload.ChangeSideChainMinGasPrice:
needRecordResult = true

default:
Expand Down

0 comments on commit 568ef32

Please sign in to comment.