44 "errors"
55 "fmt"
66 "slices"
7+ "strings"
78 "sync/atomic"
89 "time"
910
@@ -270,11 +271,16 @@ func (s *service) newPrepareResponse(preparationHash util.Uint256) dbft.PrepareR
270271 }
271272}
272273
273- func (s * service ) newChangeView (newViewNumber byte , reason dbft.ChangeViewReason , ts uint64 ) dbft.ChangeView {
274+ func (s * service ) newChangeView (newViewNumber byte , reason dbft.ChangeViewReason , ts uint64 , rejectedH ... util.Uint256 ) dbft.ChangeView {
275+ var rejected []util.Uint256
276+ if len (rejectedH ) > 0 {
277+ rejected = append (rejected , rejectedH ... )
278+ }
274279 return & changeView {
275- newViewNumber : newViewNumber ,
276- timestamp : ts / nsInMs ,
277- reason : reason ,
280+ newViewNumber : newViewNumber ,
281+ timestamp : ts / nsInMs ,
282+ reason : reason ,
283+ rejectedHashes : rejected ,
278284 }
279285}
280286
@@ -354,12 +360,14 @@ events:
354360 zap .Uint ("view" , uint (v )))
355361 s .dbft .OnTimeout (h , v )
356362 case msg := <- s .messages :
363+ log := s .log .Debug
357364 fields := []zap.Field {
358365 zap .Uint8 ("from" , msg .message .ValidatorIndex ),
359366 zap .Stringer ("type" , msg .Type ()),
360367 }
361368
362- if msg .Type () == dbft .RecoveryMessageType {
369+ switch msg .Type () {
370+ case dbft .RecoveryMessageType :
363371 rec := msg .GetRecoveryMessage ().(* recoveryMessage )
364372 if rec .preparationHash == nil {
365373 req := rec .GetPrepareRequest (& msg , s .dbft .Validators , uint16 (s .dbft .PrimaryIndex ))
@@ -375,9 +383,24 @@ events:
375383 zap .Int ("#changeview" , len (rec .changeViewPayloads )),
376384 zap .Bool ("#request" , rec .prepareRequest != nil ),
377385 zap .Bool ("#hash" , rec .preparationHash != nil ))
386+ case dbft .ChangeViewType :
387+ cv := msg .GetChangeView ().(* changeView )
388+ if len (cv .rejectedHashes ) > 0 {
389+ const maxHashes = 10
390+ var rejected strings.Builder
391+ log = s .log .Warn
392+ for _ , h := range cv .rejectedHashes [:min (len (cv .rejectedHashes ), maxHashes )] { // don't pollute logs with too many hashes.
393+ fmt .Fprintf (& rejected , "%s " , h .StringLE ())
394+ }
395+ if len (cv .rejectedHashes ) > maxHashes {
396+ rejected .WriteString ("..." )
397+ }
398+ fields = append (fields , zap .String ("rejected" , rejected .String ()))
399+ }
400+ default :
378401 }
379402
380- s . log . Debug ("received message" , fields ... )
403+ log ("received message" , fields ... )
381404 s .dbft .OnReceive (& msg )
382405 case tx := <- s .transactions :
383406 s .dbft .OnTransaction (tx )
@@ -525,26 +548,26 @@ func (s *service) getTx(h util.Uint256) dbft.Transaction[util.Uint256] {
525548 return nil
526549}
527550
528- func (s * service ) verifyBlock (b dbft.Block [util.Uint256 ]) bool {
551+ func (s * service ) verifyBlock (b dbft.Block [util.Uint256 ]) ( bool , util. Uint256 ) {
529552 coreb := & b .(* neoBlock ).Block
530553
531554 if s .Chain .BlockHeight () >= coreb .Index {
532555 s .log .Warn ("proposed block has already outdated" )
533- return false
556+ return false , util. Uint256 {}
534557 }
535558 if s .lastTimestamp >= coreb .Timestamp {
536559 s .log .Warn ("proposed block has small timestamp" ,
537560 zap .Uint64 ("ts" , coreb .Timestamp ),
538561 zap .Uint64 ("last" , s .lastTimestamp ))
539- return false
562+ return false , util. Uint256 {}
540563 }
541564
542565 size := coreb .GetExpectedBlockSize ()
543566 if size > int (s .ProtocolConfiguration .MaxBlockSize ) {
544567 s .log .Warn ("proposed block size exceeds config MaxBlockSize" ,
545568 zap .Uint32 ("max size allowed" , s .ProtocolConfiguration .MaxBlockSize ),
546569 zap .Int ("block size" , size ))
547- return false
570+ return false , util. Uint256 {}
548571 }
549572
550573 var fee int64
@@ -566,11 +589,11 @@ func (s *service) verifyBlock(b dbft.Block[util.Uint256]) bool {
566589 s .log .Warn ("invalid transaction in proposed block" ,
567590 zap .Stringer ("hash" , tx .Hash ()),
568591 zap .Error (err ))
569- return false
592+ return false , tx . Hash ()
570593 }
571594 if s .Chain .BlockHeight () >= coreb .Index {
572595 s .log .Warn ("proposed block has already outdated" )
573- return false
596+ return false , util. Uint256 {}
574597 }
575598 }
576599
@@ -579,10 +602,10 @@ func (s *service) verifyBlock(b dbft.Block[util.Uint256]) bool {
579602 s .log .Warn ("proposed block system fee exceeds config MaxBlockSystemFee" ,
580603 zap .Int ("max system fee allowed" , int (maxBlockSysFee )),
581604 zap .Int ("block system fee" , int (fee )))
582- return false
605+ return false , util. Uint256 {}
583606 }
584607
585- return true
608+ return true , util. Uint256 {}
586609}
587610
588611var (
0 commit comments