2019-11-08 15:40:21 +00:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
2024-03-21 19:49:39 +00:00
|
|
|
"github.com/nspcc-dev/dbft"
|
2020-10-02 14:25:55 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2019-11-08 15:40:21 +00:00
|
|
|
)
|
|
|
|
|
2019-11-15 10:32:40 +00:00
|
|
|
// prepareRequest represents dBFT prepareRequest message.
|
2019-11-08 15:40:21 +00:00
|
|
|
type prepareRequest struct {
|
2021-01-14 11:17:00 +00:00
|
|
|
version uint32
|
|
|
|
prevHash util.Uint256
|
2020-04-21 11:26:57 +00:00
|
|
|
timestamp uint64
|
2021-07-14 13:04:50 +00:00
|
|
|
nonce uint64
|
2019-11-15 10:32:40 +00:00
|
|
|
transactionHashes []util.Uint256
|
2020-11-17 12:57:50 +00:00
|
|
|
stateRootEnabled bool
|
|
|
|
stateRoot util.Uint256
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
2024-03-21 19:49:39 +00:00
|
|
|
var _ dbft.PrepareRequest[util.Uint256] = (*prepareRequest)(nil)
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// EncodeBinary implements the io.Serializable interface.
|
2019-11-08 15:40:21 +00:00
|
|
|
func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
|
2021-01-14 11:17:00 +00:00
|
|
|
w.WriteU32LE(p.version)
|
|
|
|
w.WriteBytes(p.prevHash[:])
|
2020-04-21 11:26:57 +00:00
|
|
|
w.WriteU64LE(p.timestamp)
|
2021-07-14 13:04:50 +00:00
|
|
|
w.WriteU64LE(p.nonce)
|
2022-06-01 08:55:16 +00:00
|
|
|
w.WriteVarUint(uint64(len(p.transactionHashes)))
|
|
|
|
for i := range p.transactionHashes {
|
|
|
|
w.WriteBytes(p.transactionHashes[i][:])
|
|
|
|
}
|
2020-11-17 12:57:50 +00:00
|
|
|
if p.stateRootEnabled {
|
|
|
|
w.WriteBytes(p.stateRoot[:])
|
|
|
|
}
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// DecodeBinary implements the io.Serializable interface.
|
2019-11-08 15:40:21 +00:00
|
|
|
func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
|
2021-01-14 11:17:00 +00:00
|
|
|
p.version = r.ReadU32LE()
|
|
|
|
r.ReadBytes(p.prevHash[:])
|
2020-04-21 11:26:57 +00:00
|
|
|
p.timestamp = r.ReadU64LE()
|
2021-07-14 13:04:50 +00:00
|
|
|
p.nonce = r.ReadU64LE()
|
2020-10-02 14:25:55 +00:00
|
|
|
r.ReadArray(&p.transactionHashes, block.MaxTransactionsPerBlock)
|
2020-11-17 12:57:50 +00:00
|
|
|
if p.stateRootEnabled {
|
|
|
|
r.ReadBytes(p.stateRoot[:])
|
|
|
|
}
|
2019-11-08 15:40:21 +00:00
|
|
|
}
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Version implements the payload.PrepareRequest interface.
|
2021-01-14 11:17:00 +00:00
|
|
|
func (p prepareRequest) Version() uint32 {
|
|
|
|
return p.version
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SetVersion implements the payload.PrepareRequest interface.
|
2021-01-14 11:17:00 +00:00
|
|
|
func (p *prepareRequest) SetVersion(v uint32) {
|
|
|
|
p.version = v
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// PrevHash implements the payload.PrepareRequest interface.
|
2021-01-14 11:17:00 +00:00
|
|
|
func (p prepareRequest) PrevHash() util.Uint256 {
|
|
|
|
return p.prevHash
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SetPrevHash implements the payload.PrepareRequest interface.
|
2021-01-14 11:17:00 +00:00
|
|
|
func (p *prepareRequest) SetPrevHash(h util.Uint256) {
|
|
|
|
p.prevHash = h
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Timestamp implements the payload.PrepareRequest interface.
|
2020-07-11 12:22:14 +00:00
|
|
|
func (p *prepareRequest) Timestamp() uint64 { return p.timestamp * nsInMs }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SetTimestamp implements the payload.PrepareRequest interface.
|
2020-07-11 12:22:14 +00:00
|
|
|
func (p *prepareRequest) SetTimestamp(ts uint64) { p.timestamp = ts / nsInMs }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// Nonce implements the payload.PrepareRequest interface.
|
2021-07-14 13:04:50 +00:00
|
|
|
func (p *prepareRequest) Nonce() uint64 { return p.nonce }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SetNonce implements the payload.PrepareRequest interface.
|
2021-07-14 13:04:50 +00:00
|
|
|
func (p *prepareRequest) SetNonce(nonce uint64) { p.nonce = nonce }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// TransactionHashes implements the payload.PrepareRequest interface.
|
2019-11-15 10:32:40 +00:00
|
|
|
func (p *prepareRequest) TransactionHashes() []util.Uint256 { return p.transactionHashes }
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SetTransactionHashes implements the payload.PrepareRequest interface.
|
2019-11-15 10:32:40 +00:00
|
|
|
func (p *prepareRequest) SetTransactionHashes(hs []util.Uint256) { p.transactionHashes = hs }
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// NextConsensus implements the payload.PrepareRequest interface.
|
2020-07-11 09:32:53 +00:00
|
|
|
func (p *prepareRequest) NextConsensus() util.Uint160 { return util.Uint160{} }
|
2019-11-15 10:32:40 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// SetNextConsensus implements the payload.PrepareRequest interface.
|
2020-07-11 09:32:53 +00:00
|
|
|
func (p *prepareRequest) SetNextConsensus(_ util.Uint160) {}
|