func (c *Client) triggerTransactions(blocksPath string, nTxs int) error { log.Lvl2("ByzCoin Client will trigger up to", nTxs, "transactions") parser, err := blockchain.NewParser(blocksPath, magicNum) if err != nil { log.Error("Error: Couldn't parse blocks in", blocksPath, ".\nPlease download bitcoin blocks as .dat files first and place them in", blocksPath, "Either run a bitcoin node (recommended) or using a torrent.") return err } transactions, err := parser.Parse(0, ReadFirstNBlocks) if err != nil { return fmt.Errorf("Error while parsing transactions %v", err) } if len(transactions) == 0 { return errors.New("Couldn't read any transactions.") } if len(transactions) < nTxs { return fmt.Errorf("Read only %v but caller wanted %v", len(transactions), nTxs) } consumed := nTxs for consumed > 0 { for _, tr := range transactions { // "send" transaction to server (we skip tcp connection on purpose here) c.srv.AddTransaction(tr) } consumed-- } return nil }
// Run runs the simulation func (e *Simulation) Run(onetConf *onet.SimulationConfig) error { doneChan := make(chan bool) doneCB := func() { doneChan <- true } // FIXME use client instead dir := blockchain.GetBlockDir() parser, err := blockchain.NewParser(dir, magicNum) if err != nil { log.Error("Error: Couldn't parse blocks in", dir) return err } transactions, err := parser.Parse(0, e.Blocksize) if err != nil { log.Error("Error while parsing transactions", err) return err } // FIXME c&p from byzcoin.go trlist := blockchain.NewTransactionList(transactions, len(transactions)) header := blockchain.NewHeader(trlist, "", "") trblock := blockchain.NewTrBlock(trlist, header) // Here we first setup the N^2 connections with a broadcast protocol pi, err := onetConf.Overlay.CreateProtocolOnet("Broadcast", onetConf.Tree) if err != nil { log.Error(err) } proto := pi.(*manage.Broadcast) // channel to notify we are done broadDone := make(chan bool) proto.RegisterOnDone(func() { broadDone <- true }) // ignore error on purpose: Start always returns nil _ = proto.Start() // wait <-broadDone log.Lvl3("Simulation can start!") for round := 0; round < e.Rounds; round++ { log.Lvl1("Starting round", round) p, err := onetConf.Overlay.CreateProtocolOnet("ByzCoinPBFT", onetConf.Tree) if err != nil { return err } proto := p.(*Protocol) proto.trBlock = trblock proto.onDoneCB = doneCB r := monitor.NewTimeMeasure("round_pbft") err = proto.Start() if err != nil { log.Error("Couldn't start PrePrepare") return err } // wait for finishing pbft: <-doneChan r.Record() log.Lvl2("Finished round", round) } return nil }