fix support for eth testnet chains (use correct tx signer)

This commit is contained in:
Ian Norden 2020-08-10 10:11:51 -05:00
parent c4876739a1
commit 52b5c99760
10 changed files with 55 additions and 16 deletions

View File

@ -22,7 +22,6 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/rpcclient"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/vulcanize/ipfs-blockchain-watcher/pkg/btc"
@ -124,14 +123,18 @@ func NewPaylaodFetcher(chain shared.ChainType, client interface{}, timeout time.
}
// NewPayloadConverter constructs a PayloadConverter for the provided chain type
func NewPayloadConverter(chain shared.ChainType) (shared.PayloadConverter, error) {
switch chain {
func NewPayloadConverter(chainType shared.ChainType, chainID uint64) (shared.PayloadConverter, error) {
switch chainType {
case shared.Ethereum:
return eth.NewPayloadConverter(params.MainnetChainConfig), nil
chainConfig, err := eth.ChainConfig(chainID)
if err != nil {
return nil, err
}
return eth.NewPayloadConverter(chainConfig), nil
case shared.Bitcoin:
return btc.NewPayloadConverter(&chaincfg.MainNetParams), nil
default:
return nil, fmt.Errorf("invalid chain %s for converter constructor", chain.String())
return nil, fmt.Errorf("invalid chain %s for converter constructor", chainType.String())
}
}
@ -188,7 +191,7 @@ func NewIPLDPublisher(chain shared.ChainType, ipfsPath string, db *postgres.DB,
}
// NewPublicAPI constructs a PublicAPI for the provided chain type
func NewPublicAPI(chain shared.ChainType, db *postgres.DB, ipfsPath string) (rpc.API, error) {
func NewPublicAPI(chain shared.ChainType, db *postgres.DB) (rpc.API, error) {
switch chain {
case shared.Ethereum:
backend, err := eth.NewEthBackend(db)

View File

@ -16,7 +16,11 @@
package eth
import "github.com/ethereum/go-ethereum/statediff"
import (
"fmt"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/statediff"
)
func ResolveFromNodeType(nodeType statediff.NodeType) int {
switch nodeType {
@ -47,3 +51,19 @@ func ResolveToNodeType(nodeType int) statediff.NodeType {
return statediff.Unknown
}
}
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
func ChainConfig(chainID uint64) (*params.ChainConfig, error) {
switch chainID {
case 1:
return params.MainnetChainConfig, nil
case 3:
return params.TestnetChainConfig, nil // Ropsten
case 4:
return params.RinkebyChainConfig, nil
case 5:
return params.GoerliChainConfig, nil
default:
return nil, fmt.Errorf("chain config for chainid %d not available", chainID)
}
}

View File

@ -72,7 +72,7 @@ func NewBackFillService(settings *Config, screenAndServeChan chan shared.Convert
if err != nil {
return nil, err
}
converter, err := builders.NewPayloadConverter(settings.Chain)
converter, err := builders.NewPayloadConverter(settings.Chain, settings.NodeInfo.ChainID)
if err != nil {
return nil, err
}

View File

@ -19,6 +19,7 @@ package node
type Node struct {
GenesisBlock string
NetworkID string
ChainID uint64
ID string
ClientName string
}

View File

@ -71,7 +71,7 @@ func NewResyncService(settings *Config) (Resync, error) {
if err != nil {
return nil, err
}
converter, err := builders.NewPayloadConverter(settings.Chain)
converter, err := builders.NewPayloadConverter(settings.Chain, settings.NodeInfo.ChainID)
if err != nil {
return nil, err
}

View File

@ -29,6 +29,7 @@ const (
Ethereum
Bitcoin
Omni
EthereumClassic
)
func (c ChainType) String() string {
@ -39,6 +40,8 @@ func (c ChainType) String() string {
return "Bitcoin"
case Omni:
return "Omni"
case EthereumClassic:
return "EthereumClassic"
default:
return ""
}
@ -52,6 +55,8 @@ func (c ChainType) API() string {
return "btc"
case Omni:
return "omni"
case EthereumClassic:
return "etc"
default:
return ""
}
@ -65,6 +70,8 @@ func NewChainType(name string) (ChainType, error) {
return Bitcoin, nil
case "omni":
return Omni, nil
case "classic", "etc":
return EthereumClassic, nil
default:
return UnknownChain, errors.New("invalid name for chain")
}

View File

@ -39,6 +39,7 @@ const (
ETH_CLIENT_NAME = "ETH_CLIENT_NAME"
ETH_GENESIS_BLOCK = "ETH_GENESIS_BLOCK"
ETH_NETWORK_ID = "ETH_NETWORK_ID"
ETH_CHAIN_ID = "ETH_CHAIN_ID"
BTC_WS_PATH = "BTC_WS_PATH"
BTC_HTTP_PATH = "BTC_HTTP_PATH"
@ -48,6 +49,7 @@ const (
BTC_CLIENT_NAME = "BTC_CLIENT_NAME"
BTC_GENESIS_BLOCK = "BTC_GENESIS_BLOCK"
BTC_NETWORK_ID = "BTC_NETWORK_ID"
BTC_CHAIN_ID = "BTC_CHAIN_ID"
)
// GetEthNodeAndClient returns eth node info and client from path url
@ -56,6 +58,7 @@ func GetEthNodeAndClient(path string) (node.Node, *rpc.Client, error) {
viper.BindEnv("ethereum.clientName", ETH_CLIENT_NAME)
viper.BindEnv("ethereum.genesisBlock", ETH_GENESIS_BLOCK)
viper.BindEnv("ethereum.networkID", ETH_NETWORK_ID)
viper.BindEnv("ethereum.chainID", ETH_CHAIN_ID)
rpcClient, err := rpc.Dial(path)
if err != nil {
@ -66,6 +69,7 @@ func GetEthNodeAndClient(path string) (node.Node, *rpc.Client, error) {
ClientName: viper.GetString("ethereum.clientName"),
GenesisBlock: viper.GetString("ethereum.genesisBlock"),
NetworkID: viper.GetString("ethereum.networkID"),
ChainID: viper.GetUint64("ethereum.chainID"),
}, rpcClient, nil
}
@ -101,6 +105,7 @@ func GetBtcNodeAndClient(path string) (node.Node, *rpcclient.ConnConfig) {
viper.BindEnv("bitcoin.networkID", BTC_NETWORK_ID)
viper.BindEnv("bitcoin.pass", BTC_NODE_PASSWORD)
viper.BindEnv("bitcoin.user", BTC_NODE_USER)
viper.BindEnv("bitcoin.chainID", BTC_CHAIN_ID)
// For bitcoin we load in node info from the config because there is no RPC endpoint to retrieve this from the node
return node.Node{
@ -108,6 +113,7 @@ func GetBtcNodeAndClient(path string) (node.Node, *rpcclient.ConnConfig) {
ClientName: viper.GetString("bitcoin.clientName"),
GenesisBlock: viper.GetString("bitcoin.genesisBlock"),
NetworkID: viper.GetString("bitcoin.networkID"),
ChainID: viper.GetUint64("bitcoin.chainID"),
}, &rpcclient.ConnConfig{
Host: path,
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode

View File

@ -16,6 +16,9 @@
package shared
// Very loose interface types for generic processing of different blockchains
// TODO: split different blockchain support into separate repos
// These types serve as very loose wrappers around a generic underlying interface{}
type RawChainData interface{}

View File

@ -1 +0,0 @@
package validate

View File

@ -108,7 +108,7 @@ func NewWatcher(settings *Config) (Watcher, error) {
if err != nil {
return nil, err
}
sn.Converter, err = builders.NewPayloadConverter(settings.Chain)
sn.Converter, err = builders.NewPayloadConverter(settings.Chain, settings.NodeInfo.ChainID)
if err != nil {
return nil, err
}
@ -154,7 +154,7 @@ func (sap *Service) Protocols() []p2p.Protocol {
// APIs returns the RPC descriptors the watcher service offers
func (sap *Service) APIs() []rpc.API {
ifnoAPI := NewInfoAPI()
infoAPI := NewInfoAPI()
apis := []rpc.API{
{
Namespace: APIName,
@ -165,23 +165,23 @@ func (sap *Service) APIs() []rpc.API {
{
Namespace: "rpc",
Version: APIVersion,
Service: ifnoAPI,
Service: infoAPI,
Public: true,
},
{
Namespace: "net",
Version: APIVersion,
Service: ifnoAPI,
Service: infoAPI,
Public: true,
},
{
Namespace: "admin",
Version: APIVersion,
Service: ifnoAPI,
Service: infoAPI,
Public: true,
},
}
chainAPI, err := builders.NewPublicAPI(sap.chain, sap.db, sap.ipfsPath)
chainAPI, err := builders.NewPublicAPI(sap.chain, sap.db)
if err != nil {
log.Error(err)
return apis