mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
tmp
This commit is contained in:
parent
a1ab4b34e8
commit
2ac62c5627
3 changed files with 42 additions and 3 deletions
|
|
@ -107,10 +107,10 @@ func (b *Balancer) Push(work Task) {
|
||||||
func (b *Balancer) balance(work chan Task) {
|
func (b *Balancer) balance(work chan Task) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case task := <-work: // get task
|
|
||||||
b.dispatch(task) // dispatch the tasks
|
|
||||||
case w := <-b.done: // worker is done
|
case w := <-b.done: // worker is done
|
||||||
b.completed(w) // handle worker
|
b.completed(w) // handle worker
|
||||||
|
case task := <-work: // get task
|
||||||
|
b.dispatch(task) // dispatch the tasks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,42 @@ type nonceResult struct {
|
||||||
valid bool
|
valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func balanceTxWork(b *balancer.Balancer, txs types.Transactions) {
|
||||||
|
if len(txs) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
workSize := len(txs) / 4
|
||||||
|
|
||||||
|
errch := make(chan error, int(math.Ceil(float64(len(txs))/float64(workSize)))) // error channel (buffered)
|
||||||
|
for i := 0; i < len(txs); i += workSize {
|
||||||
|
max := int(math.Min(float64(i+workSize), float64(len(txs)))) // get max size...
|
||||||
|
batch := txs[i:max] // ...and create batch
|
||||||
|
|
||||||
|
batchNo := i // batch number for task
|
||||||
|
// create new tasks
|
||||||
|
task := balancer.NewTask(func() error {
|
||||||
|
for i := 0; i < max-batchNo; i++ {
|
||||||
|
batch[i].FromFrontier()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}, errch)
|
||||||
|
|
||||||
|
b.Push(task)
|
||||||
|
}
|
||||||
|
|
||||||
|
// we aren't at all interested in the errors
|
||||||
|
// since we handle errors ourself.
|
||||||
|
go func() {
|
||||||
|
for i := 0; i < cap(errch); i++ {
|
||||||
|
<-errch
|
||||||
|
}
|
||||||
|
close(errch)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func balanceBlockWork(b *balancer.Balancer, blocks []*types.Block, checker pow.PoW) chan nonceResult {
|
func balanceBlockWork(b *balancer.Balancer, blocks []*types.Block, checker pow.PoW) chan nonceResult {
|
||||||
const workSize = 64
|
workSize := len(blocks) / 4
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nonceResults = make(chan nonceResult, len(blocks)) // the nonce result channel (buffered)
|
nonceResults = make(chan nonceResult, len(blocks)) // the nonce result channel (buffered)
|
||||||
|
|
|
||||||
|
|
@ -1122,7 +1122,12 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
||||||
tstart = time.Now()
|
tstart = time.Now()
|
||||||
|
|
||||||
nonceChecked = make([]bool, len(chain))
|
nonceChecked = make([]bool, len(chain))
|
||||||
|
txs types.Transactions
|
||||||
)
|
)
|
||||||
|
for _, block := range chain {
|
||||||
|
txs = append(txs, block.Transactions()...)
|
||||||
|
}
|
||||||
|
balanceTxWork(self.balancer, txs)
|
||||||
|
|
||||||
// Start the parallel nonce verifier.
|
// Start the parallel nonce verifier.
|
||||||
//nonceAbort, nonceResults := verifyNoncesFromBlocks(self.pow, chain)
|
//nonceAbort, nonceResults := verifyNoncesFromBlocks(self.pow, chain)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue