github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/helper/timeout_certificate.go (about)

     1  package helper
     2  
     3  import (
     4  	"math/rand"
     5  
     6  	hotstuff "github.com/onflow/flow-go/consensus/hotstuff/model"
     7  	"github.com/onflow/flow-go/model/flow"
     8  	"github.com/onflow/flow-go/utils/unittest"
     9  )
    10  
    11  func MakeTC(options ...func(*flow.TimeoutCertificate)) *flow.TimeoutCertificate {
    12  	qc := MakeQC()
    13  	signerIndices := unittest.SignerIndicesFixture(3)
    14  	highQCViews := make([]uint64, 3)
    15  	for i := range highQCViews {
    16  		highQCViews[i] = qc.View
    17  	}
    18  	tc := flow.TimeoutCertificate{
    19  		View:          rand.Uint64(),
    20  		NewestQC:      qc,
    21  		NewestQCViews: []uint64{qc.View},
    22  		SignerIndices: signerIndices,
    23  		SigData:       unittest.SignatureFixture(),
    24  	}
    25  	for _, option := range options {
    26  		option(&tc)
    27  	}
    28  	return &tc
    29  }
    30  
    31  func WithTCNewestQC(qc *flow.QuorumCertificate) func(*flow.TimeoutCertificate) {
    32  	return func(tc *flow.TimeoutCertificate) {
    33  		tc.NewestQC = qc
    34  		tc.NewestQCViews = []uint64{qc.View}
    35  	}
    36  }
    37  
    38  func WithTCSigners(signerIndices []byte) func(*flow.TimeoutCertificate) {
    39  	return func(tc *flow.TimeoutCertificate) {
    40  		tc.SignerIndices = signerIndices
    41  	}
    42  }
    43  
    44  func WithTCView(view uint64) func(*flow.TimeoutCertificate) {
    45  	return func(tc *flow.TimeoutCertificate) {
    46  		tc.View = view
    47  	}
    48  }
    49  
    50  func WithTCHighQCViews(highQCViews []uint64) func(*flow.TimeoutCertificate) {
    51  	return func(tc *flow.TimeoutCertificate) {
    52  		tc.NewestQCViews = highQCViews
    53  	}
    54  }
    55  
    56  func TimeoutObjectFixture(opts ...func(TimeoutObject *hotstuff.TimeoutObject)) *hotstuff.TimeoutObject {
    57  	timeout := &hotstuff.TimeoutObject{
    58  		View:       uint64(rand.Uint32()),
    59  		NewestQC:   MakeQC(),
    60  		LastViewTC: MakeTC(),
    61  		SignerID:   unittest.IdentifierFixture(),
    62  		SigData:    unittest.RandomBytes(128),
    63  	}
    64  
    65  	for _, opt := range opts {
    66  		opt(timeout)
    67  	}
    68  
    69  	return timeout
    70  }
    71  
    72  func WithTimeoutObjectSignerID(signerID flow.Identifier) func(*hotstuff.TimeoutObject) {
    73  	return func(TimeoutObject *hotstuff.TimeoutObject) {
    74  		TimeoutObject.SignerID = signerID
    75  	}
    76  }
    77  
    78  func WithTimeoutNewestQC(newestQC *flow.QuorumCertificate) func(*hotstuff.TimeoutObject) {
    79  	return func(timeout *hotstuff.TimeoutObject) {
    80  		timeout.NewestQC = newestQC
    81  	}
    82  }
    83  
    84  func WithTimeoutLastViewTC(lastViewTC *flow.TimeoutCertificate) func(*hotstuff.TimeoutObject) {
    85  	return func(timeout *hotstuff.TimeoutObject) {
    86  		timeout.LastViewTC = lastViewTC
    87  	}
    88  }
    89  
    90  func WithTimeoutObjectView(view uint64) func(*hotstuff.TimeoutObject) {
    91  	return func(TimeoutObject *hotstuff.TimeoutObject) {
    92  		TimeoutObject.View = view
    93  	}
    94  }