X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=blockchain%2Ftxbuilder%2Festimate.go;h=b769435f80c642dab39e17ce6dadee33dd09fe2d;hp=ea205a8601af959a65d3e90fd2771abd3afe9b20;hb=089cb9074ed375e28850d2ff8b5e91164a04046d;hpb=53784d9c76f1056423b57915f7e064a6f551100c diff --git a/blockchain/txbuilder/estimate.go b/blockchain/txbuilder/estimate.go index ea205a86..b769435f 100644 --- a/blockchain/txbuilder/estimate.go +++ b/blockchain/txbuilder/estimate.go @@ -4,7 +4,6 @@ import ( "github.com/vapor/consensus" "github.com/vapor/consensus/segwit" "github.com/vapor/protocol/bc/types" - "github.com/vapor/protocol/vm/vmutil" ) // EstimateTxGasInfo estimate transaction consumed gas @@ -17,7 +16,7 @@ type EstimateTxGasInfo struct { // EstimateTxGas estimate consumed neu for transaction func EstimateTxGas(template Template) (*EstimateTxGasInfo, error) { - var baseP2WSHSize, totalWitnessSize, baseP2WSHGas, totalP2WPKHGas, totalP2WSHGas, totalIssueGas int64 + var baseP2WSHSize, totalWitnessSize, baseP2WSHGas, totalP2WPKHGas, totalP2WSHGas int64 baseSize := int64(176) // inputSize(112) + outputSize(64) baseP2WPKHSize := int64(98) baseP2WPKHGas := int64(1409) @@ -33,16 +32,6 @@ func EstimateTxGas(template Template) (*EstimateTxGasInfo, error) { totalWitnessSize += baseP2WSHSize totalP2WSHGas += baseP2WSHGas } - - case types.IssuanceInputType: - issuanceProgram := input.IssuanceProgram() - if height := vmutil.GetIssuanceProgramRestrictHeight(issuanceProgram); height > 0 { - // the gas for issue program with checking block height - totalIssueGas += 5 - } - baseIssueSize, baseIssueGas := estimateIssueGas(template.SigningInstructions[pos]) - totalWitnessSize += baseIssueSize - totalIssueGas += baseIssueGas } } @@ -51,21 +40,18 @@ func EstimateTxGas(template Template) (*EstimateTxGasInfo, error) { flexibleGas += baseP2WPKHGas + (baseSize+baseP2WPKHSize)*consensus.StorageGasRate } else if totalP2WSHGas > 0 { flexibleGas += baseP2WSHGas + (baseSize+baseP2WSHSize)*consensus.StorageGasRate - } else if totalIssueGas > 0 { - totalIssueGas += baseP2WPKHGas - totalWitnessSize += baseSize + baseP2WPKHSize } // the total transaction storage gas totalTxSizeGas := (int64(template.Transaction.TxData.SerializedSize) + totalWitnessSize) * consensus.StorageGasRate // the total transaction gas is composed of storage and virtual machines - totalGas := totalTxSizeGas + totalP2WPKHGas + totalP2WSHGas + totalIssueGas + flexibleGas + totalGas := totalTxSizeGas + totalP2WPKHGas + totalP2WSHGas + flexibleGas return &EstimateTxGasInfo{ TotalNeu: totalGas * consensus.VMGasRate, FlexibleNeu: flexibleGas * consensus.VMGasRate, StorageNeu: totalTxSizeGas * consensus.VMGasRate, - VMNeu: (totalP2WPKHGas + totalP2WSHGas + totalIssueGas) * consensus.VMGasRate, + VMNeu: (totalP2WPKHGas + totalP2WSHGas) * consensus.VMGasRate, }, nil } @@ -90,19 +76,3 @@ func estimateP2WSHGas(sigInst *SigningInstruction) (int64, int64) { } return witnessSize, gas } - -// estimateIssueGas return the witness size and the gas consumed to execute the virtual machine for issuance program -func estimateIssueGas(sigInst *SigningInstruction) (int64, int64) { - var witnessSize, gas int64 - for _, witness := range sigInst.WitnessComponents { - switch t := witness.(type) { - case *SignatureWitness: - witnessSize += 65 * int64(t.Quorum) - gas += 1065*int64(len(t.Keys)) + 72*int64(t.Quorum) + 316 - case *RawTxSigWitness: - witnessSize += 65 * int64(t.Quorum) - gas += 1065*int64(len(t.Keys)) + 72*int64(t.Quorum) + 316 - } - } - return witnessSize, gas -}