diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index 9785276c6..9bb6825d4 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -64,6 +64,9 @@ type Transaction struct { // for correct signing/verification. Network netmode.Magic + // feePerByte is the ratio of NetworkFee and tx size, used for calculating tx priority. + feePerByte int64 + // Hash of the transaction (double SHA256). hash util.Uint256 @@ -278,7 +281,11 @@ func NewTransactionFromBytes(network netmode.Magic, b []byte) (*Transaction, err // FeePerByte returns NetworkFee of the transaction divided by // its size func (t *Transaction) FeePerByte() int64 { - return t.NetworkFee / int64(io.GetVarSize(t)) + if t.feePerByte != 0 { + return t.feePerByte + } + t.feePerByte = t.NetworkFee / int64(io.GetVarSize(t)) + return t.feePerByte } // transactionJSON is a wrapper for Transaction and