good morning!!!!

Skip to content
Snippets Groups Projects
Select Git revision
  • 79eaa6f2bae8c8354807a9b32b889295b0de4b6a
  • master default protected
  • v0.2.16-candidate
  • shivam/rpcAddBorTx
  • default-cli-config
  • shivam/minerRecommitFix
  • vcastellm/pos-296-bump-go-version-in-bor-and-heimdall
  • shivam/ethstats-backend-fix
  • v0.2.16-beta1-candidate
  • v0.2.15-beta3-candidate
  • shivam/newCli-IPC
  • v0.3.0-dev
  • checkpoint-whitelist-master
  • shivam/codecov
  • jdkanani/fix-typo-log
  • shivam/hardcoded-spans-v0.2.14
  • shivam/hardcoded-spans
  • shivam/fast-state-sync
  • shivam/fast-state-sync-master
  • gethv1.10.15-merge
  • fix-txpool-2
  • v0.2.14-tmp-span-hotfix
  • v0.2.15-beta2
  • v0.2.15-beta1
  • v0.3.0-beta3
  • v0.3.0-beta2
  • v0.3.0-beta1
  • v0.2.14
  • v0.2.13
  • v0.2.13-beta2
  • v0.2.13-beta1
  • v0.2.12
  • v0.2.12-beta3
  • v0.2.12-beta1
  • v0.2.12-beta2
  • v0.2.11
  • v0.2.10
  • v0.2.10-beta2
  • v0.2.9
  • v0.2.9-beta1
  • v0.2.8
41 results

block_manager.go

Blame
  • Forked from github / maticnetwork / bor
    13391 commits behind the upstream repository.
    user avatar
    Jeffrey Wilcke authored
    a1c5d5ac
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    block_manager.go 1.58 KiB
    
      // 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 {
      // Get the tx count. Used to create enough channels to 'join' the go routines
      txCount  := len(block.transactions)
      // Locking channel. When it has been fully buffered this method will return
      lockChan := make(chan bool, txCount)
    
      // Process each transaction/contract
      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" {
        bm.vm.RunTransaction(tx, func(opType OpType) bool {
          // TODO calculate fees
    
          return true // Continue
        })
      }
    
      // Broadcast we're done
      lockChan <- true
    }