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
@@ -359,7 +365,9 @@ events:
359365 zap .Stringer ("type" , msg .Type ()),
360366 }
361367
362- if msg .Type () == dbft .RecoveryMessageType {
368+ log := s .log .Debug
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,23 @@ 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+ }
378400 }
379401
380- s . log . Debug ("received message" , fields ... )
402+ log ("received message" , fields ... )
381403 s .dbft .OnReceive (& msg )
382404 case tx := <- s .transactions :
383405 s .dbft .OnTransaction (tx )
@@ -525,26 +547,26 @@ func (s *service) getTx(h util.Uint256) dbft.Transaction[util.Uint256] {
525547 return nil
526548}
527549
528- func (s * service ) verifyBlock (b dbft.Block [util.Uint256 ]) bool {
550+ func (s * service ) verifyBlock (b dbft.Block [util.Uint256 ]) ( bool , util. Uint256 ) {
529551 coreb := & b .(* neoBlock ).Block
530552
531553 if s .Chain .BlockHeight () >= coreb .Index {
532554 s .log .Warn ("proposed block has already outdated" )
533- return false
555+ return false , util. Uint256 {}
534556 }
535557 if s .lastTimestamp >= coreb .Timestamp {
536558 s .log .Warn ("proposed block has small timestamp" ,
537559 zap .Uint64 ("ts" , coreb .Timestamp ),
538560 zap .Uint64 ("last" , s .lastTimestamp ))
539- return false
561+ return false , util. Uint256 {}
540562 }
541563
542564 size := coreb .GetExpectedBlockSize ()
543565 if size > int (s .ProtocolConfiguration .MaxBlockSize ) {
544566 s .log .Warn ("proposed block size exceeds config MaxBlockSize" ,
545567 zap .Uint32 ("max size allowed" , s .ProtocolConfiguration .MaxBlockSize ),
546568 zap .Int ("block size" , size ))
547- return false
569+ return false , util. Uint256 {}
548570 }
549571
550572 var fee int64
@@ -566,11 +588,11 @@ func (s *service) verifyBlock(b dbft.Block[util.Uint256]) bool {
566588 s .log .Warn ("invalid transaction in proposed block" ,
567589 zap .Stringer ("hash" , tx .Hash ()),
568590 zap .Error (err ))
569- return false
591+ return false , tx . Hash ()
570592 }
571593 if s .Chain .BlockHeight () >= coreb .Index {
572594 s .log .Warn ("proposed block has already outdated" )
573- return false
595+ return false , util. Uint256 {}
574596 }
575597 }
576598
@@ -579,10 +601,10 @@ func (s *service) verifyBlock(b dbft.Block[util.Uint256]) bool {
579601 s .log .Warn ("proposed block system fee exceeds config MaxBlockSystemFee" ,
580602 zap .Int ("max system fee allowed" , int (maxBlockSysFee )),
581603 zap .Int ("block system fee" , int (fee )))
582- return false
604+ return false , util. Uint256 {}
583605 }
584606
585- return true
607+ return true , util. Uint256 {}
586608}
587609
588610var (
0 commit comments