Use eip155 signer for public transactions (#375)

Use eip155 for public transaction
This commit is contained in:
Qvintvs 2018-06-30 04:17:32 +08:00 committed by Samer Falah
parent f3d1315269
commit 87d7c906e9
3 changed files with 14 additions and 17 deletions

View File

@ -278,7 +278,7 @@ func (ks *KeyStore) SignTx(a accounts.Account, tx *types.Transaction, chainID *b
return nil, ErrLocked return nil, ErrLocked
} }
// Depending on the presence of the chain ID, sign with EIP155 or homestead // Depending on the presence of the chain ID, sign with EIP155 or homestead
if chainID != nil && !isQuorum { if chainID != nil && !tx.IsPrivate() {
return types.SignTx(tx, types.NewEIP155Signer(chainID), unlockedKey.PrivateKey) return types.SignTx(tx, types.NewEIP155Signer(chainID), unlockedKey.PrivateKey)
} }
return types.SignTx(tx, types.HomesteadSigner{}, unlockedKey.PrivateKey) return types.SignTx(tx, types.HomesteadSigner{}, unlockedKey.PrivateKey)

View File

@ -133,9 +133,7 @@ func isProtectedV(V *big.Int) bool {
if V.BitLen() <= 8 { if V.BitLen() <= 8 {
v := V.Uint64() v := V.Uint64()
// 27 / 28 are pre eip 155 -- ie unprotected. // 27 / 28 are pre eip 155 -- ie unprotected.
// TODO(joel): this is a hack. Everywhere else we maintain vanilla ethereum return !(v == 27 || v == 28)
// compatibility and we should figure out how to extend that to here
return !(v == 27 || v == 28 || v == 37 || v == 38)
} }
// anything not 27 or 28 are considered unprotected // anything not 27 or 28 are considered unprotected
return true return true

View File

@ -27,6 +27,9 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"net/http"
"sync"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -45,8 +48,6 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
"net/http"
"sync"
) )
const ( const (
@ -378,7 +379,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
tx := args.toTransaction() tx := args.toTransaction()
var chainID *big.Int var chainID *big.Int
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) && !isPrivate {
chainID = config.ChainId chainID = config.ChainId
} }
signed, err := wallet.SignTxWithPassphrase(account, passwd, tx, chainID) signed, err := wallet.SignTxWithPassphrase(account, passwd, tx, chainID)
@ -835,7 +836,7 @@ type RPCTransaction struct {
func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction { func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64) *RPCTransaction {
var signer types.Signer = types.HomesteadSigner{} var signer types.Signer = types.HomesteadSigner{}
// joel: this is one of the two places we used a wrong signer to print txes // joel: this is one of the two places we used a wrong signer to print txes
if tx.Protected() { if tx.Protected() && !tx.IsPrivate() {
signer = types.NewEIP155Signer(tx.ChainId()) signer = types.NewEIP155Signer(tx.ChainId())
} }
from, _ := types.Sender(signer, tx) from, _ := types.Sender(signer, tx)
@ -1005,7 +1006,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(hash common.Hash) (map[
receipt, _, _, _ := core.GetReceipt(s.b.ChainDb(), hash) // Old receipts don't have the lookup data available receipt, _, _, _ := core.GetReceipt(s.b.ChainDb(), hash) // Old receipts don't have the lookup data available
var signer types.Signer = types.HomesteadSigner{} var signer types.Signer = types.HomesteadSigner{}
if tx.Protected() { if tx.Protected() && !tx.IsPrivate() {
signer = types.NewEIP155Signer(tx.ChainId()) signer = types.NewEIP155Signer(tx.ChainId())
} }
from, _ := types.Sender(signer, tx) from, _ := types.Sender(signer, tx)
@ -1051,10 +1052,9 @@ func (s *PublicTransactionPoolAPI) sign(addr common.Address, tx *types.Transacti
} }
// Request the wallet to sign the transaction // Request the wallet to sign the transaction
var chainID *big.Int var chainID *big.Int
isQuorum := false isQuorum := tx.IsPrivate()
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) && !tx.IsPrivate() {
chainID = config.ChainId chainID = config.ChainId
isQuorum = true
} }
return wallet.SignTx(account, tx, chainID, isQuorum) return wallet.SignTx(account, tx, chainID, isQuorum)
} }
@ -1169,10 +1169,9 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
tx := args.toTransaction() tx := args.toTransaction()
var chainID *big.Int var chainID *big.Int
isQuorum := false isQuorum := tx.IsPrivate()
if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) { if config := s.b.ChainConfig(); config.IsEIP155(s.b.CurrentBlock().Number()) && !isPrivate {
chainID = config.ChainId chainID = config.ChainId
isQuorum = true
} }
signed, err := wallet.SignTx(account, tx, chainID, isQuorum) signed, err := wallet.SignTx(account, tx, chainID, isQuorum)
if err != nil { if err != nil {
@ -1257,7 +1256,7 @@ func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, err
transactions := make([]*RPCTransaction, 0, len(pending)) transactions := make([]*RPCTransaction, 0, len(pending))
for _, tx := range pending { for _, tx := range pending {
var signer types.Signer = types.HomesteadSigner{} var signer types.Signer = types.HomesteadSigner{}
if tx.Protected() { if tx.Protected() && !tx.IsPrivate() {
signer = types.NewEIP155Signer(tx.ChainId()) signer = types.NewEIP155Signer(tx.ChainId())
} }
from, _ := types.Sender(signer, tx) from, _ := types.Sender(signer, tx)
@ -1285,7 +1284,7 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxAr
for _, p := range pending { for _, p := range pending {
var signer types.Signer = types.HomesteadSigner{} var signer types.Signer = types.HomesteadSigner{}
if p.Protected() { if p.Protected() && !p.IsPrivate() {
signer = types.NewEIP155Signer(p.ChainId()) signer = types.NewEIP155Signer(p.ChainId())
} }
wantSigHash := signer.Hash(matchTx) wantSigHash := signer.Hash(matchTx)