Skip to content

Commit

Permalink
feat(bpos): change gas price from fixed64 to big.Int
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Aug 22, 2023
1 parent 5cf6cc0 commit 363670e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/transaction/crcproposaltransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bytes"
"errors"
"fmt"
"math/big"
"sort"

"github.com/elastos/Elastos.ELA/blockchain"
Expand Down Expand Up @@ -598,7 +599,7 @@ func (t *CRCProposalTransaction) checkChangeSideChainGasPriceProposal(proposal *
return errors.New("DecodePoint from OwnerKey error")
}

if proposal.MinGasPrice < 0 {
if proposal.MinGasPrice.Cmp(big.NewInt(0)) <= 0 {
return errors.New("ChangeSideChainFee invalid MinGasPrice")
}

Expand Down
12 changes: 9 additions & 3 deletions core/types/payload/crcproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bytes"
"errors"
"io"
"math/big"
"regexp"

"github.com/elastos/Elastos.ELA/common"
Expand All @@ -19,6 +20,9 @@ const (
// upgrade side chain proposal type
MinUpgradeProposalType = 0x0200
MaxUpgradeProposalType = 0x02ff

// MaxSideChainGasPriceLength is the max bytes of side chain gas price.
MaxSideChainGasPriceLength = 1024
)

const (
Expand Down Expand Up @@ -402,7 +406,7 @@ type ChangeSideChainMinGasPriceInfo struct {
GenesisBlockHash common.Uint256

// The min gas price of ESC side chain
MinGasPrice uint64
MinGasPrice big.Int

// Effective at the side chain height of ESC.
EffectiveHeight uint32
Expand All @@ -413,7 +417,7 @@ func (sc *ChangeSideChainMinGasPriceInfo) Serialize(w io.Writer) error {
return errors.New("failed to serialize GenesisBlockHash")
}

if err := common.WriteUint64(w, sc.MinGasPrice); err != nil {
if err := common.WriteVarBytes(w, sc.MinGasPrice.Bytes()); err != nil {
return errors.New("failed to serialize MinGasPrice")
}

Expand All @@ -430,9 +434,11 @@ func (sc *ChangeSideChainMinGasPriceInfo) Deserialize(r io.Reader) error {
return errors.New("failed to deserialize GenesisBlockHash")
}

if sc.MinGasPrice, err = common.ReadUint64(r); err != nil {
var minGasPriceBytes []byte
if minGasPriceBytes, err = common.ReadVarBytes(r, MaxSideChainGasPriceLength, "gas price"); err != nil {
return errors.New("failed to deserialize MinGasPrice")
}
sc.MinGasPrice.SetBytes(minGasPriceBytes)

sc.EffectiveHeight, err = common.ReadUint32(r)
if err != nil {
Expand Down

0 comments on commit 363670e

Please sign in to comment.