Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
change Umbrella to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshishuo committed Sep 18, 2018
1 parent 4576778 commit 328e7d3
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 95 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -45,3 +45,5 @@ profile.cov
/dashboard/assets/package-lock.json

**/yarn-error.log

*.swp
7 changes: 3 additions & 4 deletions core/blockchain.go
Expand Up @@ -128,7 +128,7 @@ type BlockChain struct {
processor Processor // block processor interface
validator Validator // block and state validator interface
vmConfig vm.Config
umbrella *umbrella.Umbrella // travis database interface
umbrella umbrella.Umbrella // travis database interface

badBlocks *lru.Cache // Bad block cache
}
Expand Down Expand Up @@ -166,7 +166,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
}
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, engine))
bc.SetUmbrella(umbrella.NewUmbrella())

var err error
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.getProcInterrupt)
Expand Down Expand Up @@ -1555,12 +1554,12 @@ func (bc *BlockChain) Config() *params.ChainConfig { return bc.chainConfig }
func (bc *BlockChain) Engine() consensus.Engine { return bc.engine }

// SetUmbrella sets the umbrella which is used to communacate with Travis database.
func (bc *BlockChain) SetUmbrella(umbrella *umbrella.Umbrella) {
func (bc *BlockChain) SetUmbrella(umbrella umbrella.Umbrella) {
bc.umbrella = umbrella
}

// Umbrella retrieves the blockchain's travis database interface.
func (bc *BlockChain) Umbrella() *umbrella.Umbrella {
func (bc *BlockChain) Umbrella() umbrella.Umbrella {
return bc.umbrella
}

Expand Down
2 changes: 1 addition & 1 deletion core/evm.go
Expand Up @@ -36,7 +36,7 @@ type ChainContext interface {
GetHeader(common.Hash, uint64) *types.Header

// Umbrella retrieves the Travis's database helper component.
Umbrella() *umbrella.Umbrella
Umbrella() umbrella.Umbrella
}

// NewEVMContext creates a new context for use in the EVM.
Expand Down
4 changes: 2 additions & 2 deletions core/vm/evm.go
Expand Up @@ -93,7 +93,7 @@ type Context struct {
Difficulty *big.Int // Provides information for DIFFICULTY

// Travis database helper component
Umbrella *umbrella.Umbrella
Umbrella umbrella.Umbrella
}

// EVM is the Ethereum Virtual Machine base object and provides
Expand Down Expand Up @@ -130,7 +130,7 @@ type EVM struct {
// ethereum native interface handler
eni *eni.ENI
// umbrella is a hendler to communacate with Travis database
umbrella *umbrella.Umbrella
umbrella umbrella.Umbrella
// callGasTemp holds the gas available for the current call. This is needed because the
// available gas is calculated in gasCall* according to the 63/64 rule and later
// applied in opCall*.
Expand Down
6 changes: 3 additions & 3 deletions core/vm/instructions.go
Expand Up @@ -780,9 +780,9 @@ func opIsvalidator(pc *uint64, interpreter *EVMInterpreter, contract *Contract,
addr := stack.peek()
fromAddr := common.BigToAddress(addr)
isValidator := uint64(0)
validators := interpreter.evm.Umbrella.ValidatorManager.GetValidators()
for validator := range validators {
if bytes.Equal(validator.Address.Bytes(), fromAddr.Bytes()) {
validators := interpreter.evm.Umbrella.GetValidators()
for i, _ := range validators {
if bytes.Equal(validators[i].Bytes(), fromAddr.Bytes()) {
isValidator = uint64(1)
break
}
Expand Down
37 changes: 0 additions & 37 deletions core/vm/umbrella/schedule_tx_manager.go

This file was deleted.

12 changes: 12 additions & 0 deletions core/vm/umbrella/types.go
@@ -0,0 +1,12 @@
package umbrella

import (
"github.com/ethereum/go-ethereum/common"
)

type ScheduleTx struct {
Sender common.Address
Receiver common.Address
TxData []byte
}

17 changes: 4 additions & 13 deletions core/vm/umbrella/umbrella.go
Expand Up @@ -4,17 +4,8 @@ import (
"github.com/ethereum/go-ethereum/common"
)

type Umbrella struct {
ValidatorManager *ValidatorManager
ScheduleTxManager *ScheduleTxManager
GasDiscountContracts map[common.Address]uint
}

func NewUmbrella() *Umbrella {
umbrella := &Umbrella{
ValidatorManager: NewValidatorManager(),
ScheduleTxManager: NewScheduleTxManager(),
GasDiscountContracts: make(map[common.Address]uint),
}
return umbrella
type Umbrella interface {
GetValidators() []common.Address
EmitScheduleTx(ScheduleTx)
GetDueTxs() []ScheduleTx
}
33 changes: 0 additions & 33 deletions core/vm/umbrella/validator_manager.go

This file was deleted.

4 changes: 2 additions & 2 deletions light/lightchain.go
Expand Up @@ -56,7 +56,7 @@ type LightChain struct {
chainHeadFeed event.Feed
scope event.SubscriptionScope
genesisBlock *types.Block
umbrella *umbrella.Umbrella
umbrella umbrella.Umbrella

mu sync.RWMutex
chainmu sync.RWMutex
Expand Down Expand Up @@ -137,7 +137,7 @@ func (self *LightChain) getProcInterrupt() bool {
return atomic.LoadInt32(&self.procInterrupt) == 1
}

func (self *LightChain) Umbrella() *umbrella.Umbrella {
func (self *LightChain) Umbrella() umbrella.Umbrella {
return self.umbrella
}

Expand Down

0 comments on commit 328e7d3

Please sign in to comment.