Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-ethereum/block_manager.go

59 lines
1.6 KiB

11 years ago
// Blocks, blocks will have transactions.
// Transactions/contracts are updated in goroutines
// Each contract should send a message on a channel with usage statistics
// The statics can be used for fee calculation within the block update method
// Statistics{transaction, /* integers */ normal_ops, store_load, extro_balance, crypto, steps}
// The block updater will wait for all goroutines to be finished and update the block accordingly
// in one go and should use minimal IO overhead.
// The actual block updating will happen within a goroutine as well so normal operation may continue
package main
import (
_"fmt"
)
type BlockManager struct {
vm *Vm
}
func NewBlockManager() *BlockManager {
bm := &BlockManager{vm: NewVm()}
return bm
}
// Process a block.
func (bm *BlockManager) ProcessBlock(block *Block) error {
11 years ago
// Get the tx count. Used to create enough channels to 'join' the go routines
11 years ago
txCount := len(block.transactions)
11 years ago
// Locking channel. When it has been fully buffered this method will return
11 years ago
lockChan := make(chan bool, txCount)
11 years ago
// Process each transaction/contract
11 years ago
for _, tx := range block.transactions {
go bm.ProcessTransaction(tx, lockChan)
}
// Wait for all Tx to finish processing
for i := 0; i < txCount; i++ {
<- lockChan
}
return nil
}
func (bm *BlockManager) ProcessTransaction(tx *Transaction, lockChan chan bool) {
if tx.recipient == "\x00" {
11 years ago
bm.vm.RunTransaction(tx, func(opType OpType) bool {
// TODO calculate fees
return true // Continue
})
}
// Broadcast we're done
lockChan <- true
}