From 3097dc60e56bb2e3d7fa5a33ffcbabc2f3a1604b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 3 Jul 2020 17:37:01 +0300 Subject: [PATCH] transaction: cache feePerByte --- pkg/core/transaction/transaction.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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