@@ -44,6 +44,7 @@ type Ledger interface {
4444 GetStateRoot (height uint32 ) (* state.MPTRoot , error )
4545 GetTransaction (util.Uint256 ) (* transaction.Transaction , uint32 , error )
4646 ComputeNextBlockValidators () []* keys.PublicKey
47+ IsHardforkEnabled (hf * config.Hardfork , blockHeight uint32 ) bool
4748 GetMillisecondsPerBlock () uint32
4849 PoolTx (t * transaction.Transaction , pools ... * mempool.Pool ) error
4950 SubscribeForBlocks (ch chan * coreb.Block )
@@ -216,27 +217,24 @@ var (
216217)
217218
218219// NewPayload creates a new consensus payload for the provided network.
219- func NewPayload (m netmode.Magic , stateRootEnabled bool ) * Payload {
220+ func NewPayload (m netmode.Magic ) * Payload {
220221 return & Payload {
221222 Extensible : npayload.Extensible {
222223 Category : npayload .ConsensusCategory ,
223224 },
224- message : message {
225- stateRootEnabled : stateRootEnabled ,
226- },
227225 network : m ,
228226 }
229227}
230228
231229func (s * service ) newPayload (c * dbft.Context [util.Uint256 ], t dbft.MessageType , msg any ) dbft.ConsensusPayload [util.Uint256 ] {
232- cp := NewPayload (s .ProtocolConfiguration .Magic , s . ProtocolConfiguration . StateRootInHeader )
230+ cp := NewPayload (s .ProtocolConfiguration .Magic )
233231 cp .BlockIndex = c .BlockIndex
234232 cp .message .ValidatorIndex = byte (c .MyIndex )
235233 cp .message .ViewNumber = c .ViewNumber
236234 cp .message .Type = messageType (t )
237235 if pr , ok := msg .(* prepareRequest ); ok {
238236 pr .prevHash = s .dbft .PrevHash
239- pr .version = coreb .VersionInitial
237+ pr .version = coreb .VersionInitial // TODO: ?
240238 }
241239 cp .payload = msg .(io.Serializable )
242240
@@ -249,12 +247,14 @@ func (s *service) newPayload(c *dbft.Context[util.Uint256], t dbft.MessageType,
249247
250248func (s * service ) newPrepareRequest (ts uint64 , nonce uint64 , transactionsHashes []util.Uint256 ) dbft.PrepareRequest [util.Uint256 ] {
251249 r := & prepareRequest {
250+ version : coreb .VersionInitial ,
252251 timestamp : ts / nsInMs ,
253252 nonce : nonce ,
254253 transactionHashes : transactionsHashes ,
255254 }
256- if s .ProtocolConfiguration .StateRootInHeader {
257- r .stateRootEnabled = true
255+ var f = config .HFFaun
256+ if s .Chain .IsHardforkEnabled (& f , s .dbft .BlockIndex ) {
257+ r .version = coreb .VersionFaun
258258 if sr , err := s .Chain .GetStateRoot (s .dbft .BlockIndex - 1 ); err == nil {
259259 r .stateRoot = sr .Root
260260 } else {
@@ -291,9 +291,7 @@ func (s *service) newRecoveryRequest(ts uint64) dbft.RecoveryRequest {
291291}
292292
293293func (s * service ) newRecoveryMessage () dbft.RecoveryMessage [util.Uint256 ] {
294- return & recoveryMessage {
295- stateRootEnabled : s .ProtocolConfiguration .StateRootInHeader ,
296- }
294+ return new (recoveryMessage )
297295}
298296
299297// Name returns service name.
@@ -464,9 +462,6 @@ func (s *service) getKeyPair(pubs []dbft.PublicKey) (int, dbft.PrivateKey, dbft.
464462func (s * service ) payloadFromExtensible (ep * npayload.Extensible ) * Payload {
465463 return & Payload {
466464 Extensible : * ep ,
467- message : message {
468- stateRootEnabled : s .ProtocolConfiguration .StateRootInHeader ,
469- },
470465 }
471466}
472467
@@ -597,16 +592,28 @@ func (s *service) verifyRequest(p dbft.ConsensusPayload[util.Uint256]) error {
597592 if req .prevHash != s .dbft .PrevHash {
598593 return errInvalidPrevHash
599594 }
600- if req .version != coreb .VersionInitial {
601- return errInvalidVersion
595+ var (
596+ f = config .HFFaun
597+ expectedVersion = coreb .VersionInitial
598+ )
599+ if s .Chain .IsHardforkEnabled (& f , s .dbft .BlockIndex ) {
600+ expectedVersion = coreb .VersionFaun
601+ }
602+ if req .version != expectedVersion {
603+ return fmt .Errorf ("%w: expected %d, got %d" , errInvalidVersion , expectedVersion , req .version )
602604 }
603- if s . ProtocolConfiguration . StateRootInHeader {
605+ if req . version == coreb . VersionFaun {
604606 sr , err := s .Chain .GetStateRoot (s .dbft .BlockIndex - 1 )
605607 if err != nil {
606608 return err
607609 } else if sr .Root != req .stateRoot {
608610 return fmt .Errorf ("%w: %s != %s" , errInvalidStateRoot , sr .Root , req .stateRoot )
609611 }
612+ } else {
613+ // TODO: port this check to C# node:
614+ if ! req .stateRoot .Equals (util.Uint256 {}) {
615+ return fmt .Errorf ("stateroot is not empty, but Faun is not enabled yet: %s" , req .stateRoot )
616+ }
610617 }
611618 if len (req .TransactionHashes ()) > int (s .ProtocolConfiguration .MaxTransactionsPerBlock ) {
612619 return fmt .Errorf ("%w: max = %d, got %d" , errInvalidTransactionsCount , s .ProtocolConfiguration .MaxTransactionsPerBlock , len (req .TransactionHashes ()))
@@ -756,17 +763,23 @@ func convertKeys(validators []dbft.PublicKey) (pubs []*keys.PublicKey) {
756763}
757764
758765func (s * service ) newBlockFromContext (ctx * dbft.Context [util.Uint256 ]) dbft.Block [util.Uint256 ] {
759- block := & neoBlock {network : s .ProtocolConfiguration .Magic }
766+ var (
767+ blockVersion = coreb .VersionInitial
768+ block = & neoBlock {network : s .ProtocolConfiguration .Magic }
769+ )
760770
771+ hff , ok := s .ProtocolConfiguration .Hardforks [config .HFFaun .String ()]
772+ if ok && hff <= ctx .BlockIndex {
773+ blockVersion = coreb .VersionFaun
774+ }
761775 block .Block .Timestamp = ctx .Timestamp / nsInMs
762776 block .Nonce = ctx .Nonce
763777 block .Block .Index = ctx .BlockIndex
764- if s . ProtocolConfiguration . StateRootInHeader {
778+ if blockVersion > coreb . VersionInitial {
765779 sr , err := s .Chain .GetStateRoot (ctx .BlockIndex - 1 )
766780 if err != nil {
767781 s .log .Fatal (fmt .Sprintf ("failed to get state root: %s" , err .Error ()))
768782 }
769- block .StateRootEnabled = true
770783 block .PrevStateRoot = sr .Root
771784 }
772785
@@ -787,7 +800,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context[util.Uint256]) dbft.Bloc
787800 }
788801 block .NextConsensus = hash .Hash160 (script )
789802 block .Block .PrevHash = ctx .PrevHash
790- block .Version = coreb . VersionInitial
803+ block .Version = blockVersion
791804
792805 primaryIndex := byte (ctx .PrimaryIndex )
793806 block .PrimaryIndex = primaryIndex
0 commit comments