github.com/MetalBlockchain/metalgo@v1.11.9/snow/consensus/snowball/consensus_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package snowball 5 6 import ( 7 "github.com/MetalBlockchain/metalgo/ids" 8 "github.com/MetalBlockchain/metalgo/utils/bag" 9 ) 10 11 var ( 12 Red = ids.Empty.Prefix(0) 13 Blue = ids.Empty.Prefix(1) 14 Green = ids.Empty.Prefix(2) 15 16 _ Consensus = (*Byzantine)(nil) 17 ) 18 19 func NewByzantine(_ Factory, _ Parameters, choice ids.ID) Consensus { 20 return &Byzantine{ 21 preference: choice, 22 } 23 } 24 25 // Byzantine is a naive implementation of a multi-choice snowball instance 26 type Byzantine struct { 27 // Hardcode the preference 28 preference ids.ID 29 } 30 31 func (*Byzantine) Add(ids.ID) {} 32 33 func (b *Byzantine) Preference() ids.ID { 34 return b.preference 35 } 36 37 func (*Byzantine) RecordPoll(bag.Bag[ids.ID]) bool { 38 return false 39 } 40 41 func (*Byzantine) RecordUnsuccessfulPoll() {} 42 43 func (*Byzantine) Finalized() bool { 44 return true 45 } 46 47 func (b *Byzantine) String() string { 48 return b.preference.String() 49 }