Skip to content
Snippets Groups Projects
Select Git revision
  • ec373339c12b815ac0a80c8720d602740607f709
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

fpc.go

Blame
  • fpc.go 5.42 KiB
    package valuetransfers
    
    import (
    	"context"
    	"flag"
    	"fmt"
    	"net"
    	"strconv"
    
    	"github.com/iotaledger/hive.go/autopeering/peer"
    	"github.com/iotaledger/hive.go/daemon"
    	"github.com/iotaledger/hive.go/events"
    	"github.com/iotaledger/hive.go/logger"
    	"google.golang.org/grpc"
    
    	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager"
    	"github.com/iotaledger/goshimmer/packages/prng"
    	"github.com/iotaledger/goshimmer/packages/shutdown"
    	"github.com/iotaledger/goshimmer/packages/vote"
    	"github.com/iotaledger/goshimmer/packages/vote/fpc"
    	votenet "github.com/iotaledger/goshimmer/packages/vote/net"
    	"github.com/iotaledger/goshimmer/plugins/autopeering"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/local"
    	"github.com/iotaledger/goshimmer/plugins/config"
    
    	"sync"
    
    	"github.com/iotaledger/hive.go/autopeering/peer/service"
    )
    
    const (
    	CfgFPCQuerySampleSize = "fpc.querySampleSize"
    	CfgFPCRoundInterval   = "fpc.roundInterval"
    	CfgFPCBindAddress     = "fpc.bindAddress"
    )
    
    func init() {
    	flag.Int(CfgFPCQuerySampleSize, 3, "Size of the voting quorum (k)")
    	flag.Int(CfgFPCRoundInterval, 5, "FPC round interval [s]")
    	flag.String(CfgFPCBindAddress, "0.0.0.0:10895", "the bind address on which the FPC vote server binds to")
    }
    
    var (
    	voter                *fpc.FPC
    	voterOnce            sync.Once
    	voterServer          *votenet.VoterServer
    	roundIntervalSeconds int64 = 5
    )
    
    // Voter returns the DRNGRoundBasedVoter instance used by the FPC plugin.
    func Voter() vote.DRNGRoundBasedVoter {
    	voterOnce.Do(func() {
    		// create a function which gets OpinionGivers
    		opinionGiverFunc := func() (givers []vote.OpinionGiver, err error) {
    			opinionGivers := make([]vote.OpinionGiver, 0)
    			for _, p := range autopeering.Discovery.GetVerifiedPeers() {
    				fpcService := p.Services().Get(service.FPCKey)
    				if fpcService == nil {
    					continue
    				}
    				// TODO: maybe cache the PeerOpinionGiver instead of creating a new one every time
    				opinionGivers = append(opinionGivers, &PeerOpinionGiver{p: p})
    			}
    			return opinionGivers, nil
    		}
    		voter = fpc.New(opinionGiverFunc)
    	})
    	return voter
    }