transaction: cache feePerByte

This commit is contained in:
Evgenii Stratonikov 2020-07-03 17:37:01 +03:00
parent 2f09ec38fc
commit 3097dc60e5

View file

@ -64,6 +64,9 @@ type Transaction struct {
// for correct signing/verification. // for correct signing/verification.
Network netmode.Magic 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 of the transaction (double SHA256).
hash util.Uint256 hash util.Uint256
@ -278,7 +281,11 @@ func NewTransactionFromBytes(network netmode.Magic, b []byte) (*Transaction, err
// FeePerByte returns NetworkFee of the transaction divided by // FeePerByte returns NetworkFee of the transaction divided by
// its size // its size
func (t *Transaction) FeePerByte() int64 { 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 // transactionJSON is a wrapper for Transaction and