Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent sender address with address mapping. #1589

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change parameters
  • Loading branch information
Sriep committed Nov 27, 2019
commit 8d34f4290fc7f276315329bd66d7f04b17695bed
27 changes: 10 additions & 17 deletions eth/polls/eth_subscribe.go
Original file line number Diff line number Diff line change
@@ -6,9 +6,8 @@ import (
"fmt"
"sync"

"github.com/loomnetwork/go-loom/plugin/contractpb"
"github.com/loomnetwork/go-loom"

"github.com/loomnetwork/loomchain/auth"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"

"github.com/loomnetwork/loomchain/store"
@@ -27,22 +26,19 @@ type EthPoll interface {
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (interface{}, error)
Poll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, interface{}, error)
LegacyPoll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, []byte, error)
}

@@ -135,25 +131,23 @@ func (s *EthSubscriptions) AllLogs(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (interface{}, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()

if poll, ok := s.polls[id]; !ok {
return nil, fmt.Errorf("subscription not found")
} else {
return poll.AllLogs(state, id, readReceipts, authCfg, createAddressMapperCtx)
return poll.AllLogs(state, id, readReceipts, resolveAccountToLocalAddr)
}
}

func (s *EthSubscriptions) Poll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (interface{}, error) {
s.mutex.Lock()
defer s.mutex.Unlock()
@@ -162,7 +156,7 @@ func (s *EthSubscriptions) Poll(
if !ok {
return nil, fmt.Errorf("subscription not found")
}
newPoll, result, err := poll.Poll(state, id, readReceipts, authCfg, createAddressMapperCtx)
newPoll, result, err := poll.Poll(state, id, readReceipts, resolveAccountToLocalAddr)
s.polls[id] = newPoll

s.resetTimestamp(id, uint64(state.Block().Height))
@@ -174,8 +168,7 @@ func (s *EthSubscriptions) LegacyPoll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) ([]byte, error) {
s.mutex.Lock()
defer s.mutex.Unlock()
@@ -184,7 +177,7 @@ func (s *EthSubscriptions) LegacyPoll(
if !ok {
return nil, fmt.Errorf("subscription not found")
}
newPoll, result, err := poll.LegacyPoll(state, id, readReceipts, authCfg, createAddressMapperCtx)
newPoll, result, err := poll.LegacyPoll(state, id, readReceipts, resolveAccountToLocalAddr)
s.polls[id] = newPoll

s.resetTimestamp(id, uint64(state.Block().Height))
13 changes: 5 additions & 8 deletions eth/polls/pollblocks.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,10 @@ package polls

import (
"github.com/gogo/protobuf/proto"
"github.com/loomnetwork/go-loom/plugin/contractpb"
"github.com/loomnetwork/go-loom"
"github.com/loomnetwork/go-loom/plugin/types"
"github.com/loomnetwork/loomchain"
"github.com/loomnetwork/loomchain/auth"

"github.com/loomnetwork/loomchain/rpc/eth"
"github.com/loomnetwork/loomchain/store"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"
@@ -35,8 +35,7 @@ func (p *EthBlockPoll) Poll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
_ *auth.Config,
_ func(state loomchain.State) (contractpb.StaticContext, error),
_ func(loomchain.State, loom.Address) (loom.Address, error),

) (EthPoll, interface{}, error) {
if p.lastBlock+1 > uint64(state.Block().Height) {
@@ -54,8 +53,7 @@ func (p *EthBlockPoll) AllLogs(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
_ *auth.Config,
_ func(state loomchain.State) (contractpb.StaticContext, error),
_ func(loomchain.State, loom.Address) (loom.Address, error),
) (interface{}, error) {
_, results, err := getBlockHashes(p.blockStore, state, p.startBlock)
return eth.EncBytesArray(results), err
@@ -85,8 +83,7 @@ func (p *EthBlockPoll) LegacyPoll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
_ *auth.Config,
_ func(state loomchain.State) (contractpb.StaticContext, error),
_ func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, []byte, error) {
if p.lastBlock+1 > uint64(state.Block().Height) {
return p, nil, nil
23 changes: 9 additions & 14 deletions eth/polls/polllogs.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,8 @@ package polls
import (
"fmt"

"github.com/loomnetwork/go-loom/plugin/contractpb"
"github.com/loomnetwork/go-loom"

"github.com/pkg/errors"

"github.com/loomnetwork/loomchain/store"
@@ -14,7 +15,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/loomnetwork/go-loom/plugin/types"
"github.com/loomnetwork/loomchain"
"github.com/loomnetwork/loomchain/auth"

"github.com/loomnetwork/loomchain/eth/query"
"github.com/loomnetwork/loomchain/eth/utils"
"github.com/loomnetwork/loomchain/rpc/eth"
@@ -45,8 +46,7 @@ func (p *EthLogPoll) Poll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, interface{}, error) {
start, err := eth.DecBlockHeight(state.Block().Height, p.filter.FromBlock)
if err != nil {
@@ -76,8 +76,7 @@ func (p *EthLogPoll) Poll(
p.filter.EthBlockFilter,
readReceipts,
p.evmAuxStore,
authCfg,
createAddressMapperCtx,
resolveAccountToLocalAddr,
)
if err != nil {
return p, nil, err
@@ -93,8 +92,7 @@ func (p *EthLogPoll) AllLogs(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (interface{}, error) {
start, err := eth.DecBlockHeight(state.Block().Height, p.filter.FromBlock)
if err != nil {
@@ -116,8 +114,7 @@ func (p *EthLogPoll) AllLogs(
p.filter.EthBlockFilter,
readReceipts,
p.evmAuxStore,
authCfg,
createAddressMapperCtx,
resolveAccountToLocalAddr,
)
if err != nil {
return nil, err
@@ -129,8 +126,7 @@ func (p *EthLogPoll) LegacyPoll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
authCfg *auth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, []byte, error) {
start, err := eth.DecBlockHeight(state.Block().Height, p.filter.FromBlock)
if err != nil {
@@ -156,8 +152,7 @@ func (p *EthLogPoll) LegacyPoll(
p.filter.EthBlockFilter,
readReceipts,
p.evmAuxStore,
authCfg,
createAddressMapperCtx,
resolveAccountToLocalAddr,
)
if err != nil {
return p, nil, err
13 changes: 5 additions & 8 deletions eth/polls/polltx.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,10 @@ package polls

import (
"github.com/gogo/protobuf/proto"
"github.com/loomnetwork/go-loom/plugin/contractpb"
"github.com/loomnetwork/go-loom"
"github.com/loomnetwork/go-loom/plugin/types"
"github.com/loomnetwork/loomchain"
"github.com/loomnetwork/loomchain/auth"

"github.com/loomnetwork/loomchain/rpc/eth"
"github.com/loomnetwork/loomchain/store"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"
@@ -35,8 +35,7 @@ func (p *EthTxPoll) Poll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
_ *auth.Config,
_ func(state loomchain.State) (contractpb.StaticContext, error),
_ func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, interface{}, error) {
if p.lastBlockRead+1 > uint64(state.Block().Height) {
return p, nil, nil
@@ -53,8 +52,7 @@ func (p *EthTxPoll) AllLogs(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
_ *auth.Config,
_ func(state loomchain.State) (contractpb.StaticContext, error),
_ func(loomchain.State, loom.Address) (loom.Address, error),
) (interface{}, error) {
_, results, err := getTxHashes(state, p.startBlock, readReceipts, p.evmAuxStore)
return eth.EncBytesArray(results), err
@@ -81,8 +79,7 @@ func (p *EthTxPoll) LegacyPoll(
state loomchain.State,
id string,
readReceipts loomchain.ReadReceiptHandler,
_ *auth.Config,
_ func(state loomchain.State) (contractpb.StaticContext, error),
_ func(loomchain.State, loom.Address) (loom.Address, error),
) (EthPoll, []byte, error) {
if p.lastBlockRead+1 > uint64(state.Block().Height) {
return p, nil, nil
18 changes: 7 additions & 11 deletions eth/query/block.go
Original file line number Diff line number Diff line change
@@ -11,17 +11,16 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/loomnetwork/go-loom"
"github.com/loomnetwork/go-loom/auth"
"github.com/loomnetwork/go-loom/plugin/contractpb"
"github.com/loomnetwork/go-loom/plugin/types"
ltypes "github.com/loomnetwork/go-loom/types"
"github.com/loomnetwork/go-loom/vm"
"github.com/pkg/errors"
ctypes "github.com/tendermint/tendermint/rpc/core/types"

"github.com/loomnetwork/loomchain"
lauth "github.com/loomnetwork/loomchain/auth"
"github.com/loomnetwork/loomchain/rpc/eth"
"github.com/loomnetwork/loomchain/store"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"
"github.com/pkg/errors"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)

var (
@@ -34,8 +33,7 @@ func GetBlockByNumber(
height int64,
full bool,
evmAuxStore *evmaux.EvmAuxStore,
authCfg *lauth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (resp eth.JsonBlockObject, err error) {
// todo make information about pending block available
if height > state.Block().Height {
@@ -110,8 +108,7 @@ func GetBlockByNumber(
int64(index),
evmAuxStore,
state,
authCfg,
createAddressMapperCtx,
resolveAccountToLocalAddr,
)
if err != nil {
return resp, errors.Wrapf(err, "failed to decode tx, hash %X", tx.Hash())
@@ -137,8 +134,7 @@ func GetTxObjectFromBlockResult(
txIndex int64,
evmAuxStore *evmaux.EvmAuxStore,
state loomchain.State,
authCfg *lauth.Config,
createAddressMapperCtx func(state loomchain.State) (contractpb.StaticContext, error),
resolveAccountToLocalAddr func(loomchain.State, loom.Address) (loom.Address, error),
) (eth.JsonTxObject, *eth.Data, error) {
tx := blockResult.Block.Data.Txs[txIndex]
var contractAddress *eth.Data
@@ -173,7 +169,7 @@ func GetTxObjectFromBlockResult(
return eth.GetEmptyTxObject(), nil, err
}

addr, err := lauth.ResolveAccountAddress(loom.UnmarshalAddressPB(msg.From), state, authCfg, createAddressMapperCtx)
addr, err := resolveAccountToLocalAddr(state, loom.UnmarshalAddressPB(msg.From))
if err != nil {
return eth.GetEmptyTxObject(), nil, err
}
Loading