}
// BeforeProposalBlock return all transactions than can be matched, and the number of transactions cannot exceed the given capacity.
-func (m *MovCore) BeforeProposalBlock(nodeProgram []byte, gasLeft int64, calcGasUsed func(*types.Tx) (int64, error)) ([]*types.Tx, int64, error) {
+func (m *MovCore) BeforeProposalBlock(nodeProgram []byte, gasLeft int64) ([]*types.Tx, int64, error) {
matchEngine := match.NewEngine(m.movStore, maxFeeRate, nodeProgram)
tradePairMap := make(map[string]bool)
tradePairIterator := database.NewTradePairIterator(m.movStore)
return nil, 0, err
}
- gasUsed, err := calcGasUsed(matchedTx)
- if err != nil {
- return nil, 0, err
+ gasUsed := calcMatchedTxGasUsed(matchedTx)
+ if gasLeft - gasUsed >= 0 {
+ packagedTxs = append(packagedTxs, matchedTx)
}
-
- packagedTxs = append(packagedTxs, matchedTx)
gasLeft -= gasUsed
}
}
return packagedTxs, gasLeft, nil
}
+func calcMatchedTxGasUsed(tx *types.Tx) int64 {
+ return int64(len(tx.Inputs)) * 150 + int64(tx.SerializedSize)
+}
+
// IsDust block the transaction that are not generated by the match engine
func (m *MovCore) IsDust(tx *types.Tx) bool {
for _, input := range tx.Inputs {
break
}
- subTxs, gasLeft, err = p.BeforeProposalBlock(cp, gasLeft, calcGasUsed(&bc.Block{BlockHeader: &bc.BlockHeader{Height: chain.BestBlockHeight() + 1}}))
+ subTxs, gasLeft, err = p.BeforeProposalBlock(cp, gasLeft)
if err != nil {
log.WithFields(log.Fields{"module": logModule, "index": i, "error": err}).Error("failed on sub protocol txs package")
continue
return result, nil
}
-func calcGasUsed(bcBlock *bc.Block) func (*types.Tx) (int64, error) {
- return func (tx *types.Tx) (int64, error) {
- gasState, err := validation.ValidateTx(tx.Tx, bcBlock)
- if err != nil {
- return 0, err
- }
-
- return gasState.GasUsed, nil
- }
-}
-
func blkGenSkipTxForErr(txPool *protocol.TxPool, txHash *bc.Hash, err error) {
log.WithFields(log.Fields{"module": logModule, "error": err}).Error("mining block generation: skip tx due to")
txPool.RemoveTransaction(txHash)
type Protocoler interface {
Name() string
- BeforeProposalBlock(nodeProgram []byte, gasLeft int64, calcGasUsed func(*types.Tx) (int64, error)) ([]*types.Tx, int64, error)
+ BeforeProposalBlock(nodeProgram []byte, gasLeft int64) ([]*types.Tx, int64, error)
ChainStatus() (uint64, *bc.Hash, error)
ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error
ValidateTxs(txs []*types.Tx, verifyResults []*bc.TxVerifyResult) error