Skip to content

Commit

Permalink
Merge pull request ethereum#6 from jpmorganchase/privpub
Browse files Browse the repository at this point in the history
eth: look in private an public state on reading state data
  • Loading branch information
patrickmn authored Nov 16, 2016
2 parents f4b5a8c + c371524 commit 1491101
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/quorum/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (api *PublicQuorumAPI) CanonicalHash(height rpc.HexNumber) (common.Hash, er
}

func (api *PublicQuorumAPI) Vote(blockHash common.Hash) (common.Hash, error) {
pBlock, _ := api.bv.Pending()
pBlock, _, _ := api.bv.Pending()

req := Vote{
Hash: blockHash,
Expand Down
4 changes: 2 additions & 2 deletions core/quorum/block_voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ func (bv *BlockVoting) applyTransaction(tx *types.Transaction) {
bv.pStateMu.Unlock()
}

func (bv *BlockVoting) Pending() (*types.Block, *state.StateDB) {
func (bv *BlockVoting) Pending() (*types.Block, *state.StateDB, *state.StateDB) {
bv.pStateMu.Lock()
defer bv.pStateMu.Unlock()
return types.NewBlock(bv.pState.header, bv.pState.txs, nil, bv.pState.receipts), bv.pState.publicState.Copy()
return types.NewBlock(bv.pState.header, bv.pState.txs, nil, bv.pState.receipts), bv.pState.publicState.Copy(), bv.pState.privateState.Copy()
}

func (bv *BlockVoting) createBlock() (*types.Block, error) {
Expand Down
30 changes: 21 additions & 9 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (b *EthApiBackend) SetHead(number uint64) {
func (b *EthApiBackend) HeaderByNumber(blockNr rpc.BlockNumber) *types.Header {
// Pending block is only known by the miner
if blockNr == rpc.PendingBlockNumber {
block, _ := b.eth.blockVoting.Pending()
block, _, _ := b.eth.blockVoting.Pending()
return block.Header()
}
// Otherwise resolve and return the block
Expand All @@ -58,7 +58,7 @@ func (b *EthApiBackend) HeaderByNumber(blockNr rpc.BlockNumber) *types.Header {
func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) {
// Pending block is only known by the miner
if blockNr == rpc.PendingBlockNumber {
block, _ := b.eth.blockVoting.Pending()
block, _, _ := b.eth.blockVoting.Pending()
return block, nil
}
// Otherwise resolve and return the block
Expand All @@ -71,8 +71,8 @@ func (b *EthApiBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb
func (b *EthApiBackend) StateAndHeaderByNumber(blockNr rpc.BlockNumber) (ethapi.State, *types.Header, error) {
// Pending state is only known by the miner
if blockNr == rpc.PendingBlockNumber {
block, state := b.eth.blockVoting.Pending()
return EthApiState{state, state}, block.Header(), nil
block, publicState, privateState := b.eth.blockVoting.Pending()
return EthApiState{publicState, privateState}, block.Header(), nil
}
// Otherwise resolve the block number and return its state
header := b.HeaderByNumber(blockNr)
Expand Down Expand Up @@ -103,7 +103,7 @@ func (b *EthApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state et
)

addr, _ := msg.From()
if !privateState.Exist(addr) {
if publicState.Exist(addr) {
privateState = publicState
}
from := privateState.GetOrNewStateObject(addr)
Expand Down Expand Up @@ -195,17 +195,29 @@ type EthApiState struct {
}

func (s EthApiState) GetBalance(ctx context.Context, addr common.Address) (*big.Int, error) {
return s.publicState.GetBalance(addr), nil
if s.publicState.Exist(addr) {
return s.publicState.GetBalance(addr), nil
}
return s.privateState.GetBalance(addr), nil
}

func (s EthApiState) GetCode(ctx context.Context, addr common.Address) ([]byte, error) {
return s.publicState.GetCode(addr), nil
if s.publicState.Exist(addr) {
return s.publicState.GetCode(addr), nil
}
return s.privateState.GetCode(addr), nil
}

func (s EthApiState) GetState(ctx context.Context, a common.Address, b common.Hash) (common.Hash, error) {
return s.publicState.GetState(a, b), nil
if s.publicState.Exist(a) {
return s.publicState.GetState(a, b), nil
}
return s.privateState.GetState(a, b), nil
}

func (s EthApiState) GetNonce(ctx context.Context, addr common.Address) (uint64, error) {
return s.publicState.GetNonce(addr), nil
if s.publicState.Exist(addr) {
return s.publicState.GetNonce(addr), nil
}
return s.privateState.GetNonce(addr), nil
}

0 comments on commit 1491101

Please sign in to comment.