2019-01-28 08:45:28 +00:00
|
|
|
// Package powchain defines the services that interact with the ETH1.0 of Ethereum.
|
2018-07-14 19:48:42 +00:00
|
|
|
package powchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-01-16 14:01:21 +00:00
|
|
|
"encoding/binary"
|
|
|
|
"errors"
|
2018-07-14 19:48:42 +00:00
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
"strings"
|
2019-01-17 15:14:32 +00:00
|
|
|
"time"
|
2018-07-14 19:48:42 +00:00
|
|
|
|
2019-02-03 22:44:48 +00:00
|
|
|
ethereum "github.com/ethereum/go-ethereum"
|
2019-01-16 14:01:21 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
2018-07-14 19:48:42 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
2019-01-16 14:01:21 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
2019-02-05 17:25:09 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
2019-01-28 08:45:28 +00:00
|
|
|
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
2019-02-03 22:44:48 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2019-01-28 11:59:37 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/event"
|
2019-01-16 14:01:21 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
2019-01-31 02:53:58 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
2018-07-21 17:51:18 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-07-14 19:48:42 +00:00
|
|
|
)
|
|
|
|
|
2018-07-21 17:51:18 +00:00
|
|
|
var log = logrus.WithField("prefix", "powchain")
|
|
|
|
|
2018-10-18 17:33:38 +00:00
|
|
|
// Reader defines a struct that can fetch latest header events from a web3 endpoint.
|
|
|
|
type Reader interface {
|
|
|
|
SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// POWBlockFetcher defines a struct that can retrieve mainchain blocks.
|
|
|
|
type POWBlockFetcher interface {
|
|
|
|
BlockByHash(ctx context.Context, hash common.Hash) (*gethTypes.Block, error)
|
|
|
|
}
|
|
|
|
|
2019-01-28 08:45:28 +00:00
|
|
|
// Client defines a struct that combines all relevant ETH1.0 mainchain interactions required
|
2018-10-18 17:33:38 +00:00
|
|
|
// by the beacon chain node.
|
|
|
|
type Client interface {
|
|
|
|
Reader
|
|
|
|
POWBlockFetcher
|
2019-01-16 14:01:21 +00:00
|
|
|
bind.ContractFilterer
|
|
|
|
bind.ContractCaller
|
2018-10-18 17:33:38 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 19:48:42 +00:00
|
|
|
// Web3Service fetches important information about the canonical
|
2019-01-28 08:45:28 +00:00
|
|
|
// Ethereum ETH1.0 chain via a web3 endpoint using an ethclient. The Random
|
|
|
|
// Beacon Chain requires synchronization with the ETH1.0 chain's current
|
2018-07-14 19:48:42 +00:00
|
|
|
// blockhash, block number, and access to logs within the
|
2019-01-28 08:45:28 +00:00
|
|
|
// Validator Registration Contract on the ETH1.0 chain to kick off the beacon
|
2018-07-14 19:48:42 +00:00
|
|
|
// chain's validator registration process.
|
|
|
|
type Web3Service struct {
|
2019-01-17 15:14:32 +00:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
client Client
|
|
|
|
headerChan chan *gethTypes.Header
|
|
|
|
logChan chan gethTypes.Log
|
|
|
|
endpoint string
|
|
|
|
depositContractAddress common.Address
|
2019-01-28 11:59:37 +00:00
|
|
|
chainStartFeed *event.Feed
|
2019-01-17 15:14:32 +00:00
|
|
|
reader Reader
|
|
|
|
logger bind.ContractFilterer
|
2019-01-28 08:45:28 +00:00
|
|
|
blockNumber *big.Int // the latest ETH1.0 chain blockNumber.
|
|
|
|
blockHash common.Hash // the latest ETH1.0 chain blockHash.
|
|
|
|
vrcCaller *contracts.DepositContractCaller
|
2019-01-17 15:14:32 +00:00
|
|
|
depositRoot []byte
|
2019-01-31 02:53:58 +00:00
|
|
|
depositTrie *trieutil.DepositTrie
|
2019-02-03 22:44:48 +00:00
|
|
|
chainStartDeposits []*pb.Deposit
|
|
|
|
chainStarted bool
|
2019-02-05 17:25:09 +00:00
|
|
|
beaconDB *db.BeaconDB
|
2018-07-19 16:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Web3ServiceConfig defines a config struct for web3 service to use through its life cycle.
|
|
|
|
type Web3ServiceConfig struct {
|
2019-01-16 14:01:21 +00:00
|
|
|
Endpoint string
|
2019-01-17 15:14:32 +00:00
|
|
|
DepositContract common.Address
|
2019-01-16 14:01:21 +00:00
|
|
|
Client Client
|
|
|
|
Reader Reader
|
|
|
|
Logger bind.ContractFilterer
|
|
|
|
ContractBackend bind.ContractBackend
|
2019-02-05 17:25:09 +00:00
|
|
|
BeaconDB *db.BeaconDB
|
2018-07-14 19:48:42 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
var (
|
2019-01-28 08:45:28 +00:00
|
|
|
depositEventSignature = []byte("Deposit(bytes32,bytes,bytes)")
|
|
|
|
chainStartEventSignature = []byte("ChainStart(bytes32,bytes)")
|
2019-01-16 14:01:21 +00:00
|
|
|
)
|
|
|
|
|
2018-07-14 19:48:42 +00:00
|
|
|
// NewWeb3Service sets up a new instance with an ethclient when
|
2018-08-09 18:25:48 +00:00
|
|
|
// given a web3 endpoint as a string in the config.
|
2018-11-16 17:01:41 +00:00
|
|
|
func NewWeb3Service(ctx context.Context, config *Web3ServiceConfig) (*Web3Service, error) {
|
2018-07-19 16:31:50 +00:00
|
|
|
if !strings.HasPrefix(config.Endpoint, "ws") && !strings.HasPrefix(config.Endpoint, "ipc") {
|
2018-11-16 17:01:41 +00:00
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"web3service requires either an IPC or WebSocket endpoint, provided %s",
|
|
|
|
config.Endpoint,
|
|
|
|
)
|
2018-07-14 19:48:42 +00:00
|
|
|
}
|
2019-01-16 14:01:21 +00:00
|
|
|
|
2019-01-28 08:45:28 +00:00
|
|
|
vrcCaller, err := contracts.NewDepositContractCaller(config.DepositContract, config.ContractBackend)
|
2019-01-16 14:01:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not create VRC caller %v", err)
|
|
|
|
}
|
|
|
|
|
2018-07-31 04:41:27 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
2018-07-14 19:48:42 +00:00
|
|
|
return &Web3Service{
|
2019-01-17 15:14:32 +00:00
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
|
|
|
headerChan: make(chan *gethTypes.Header),
|
|
|
|
logChan: make(chan gethTypes.Log),
|
|
|
|
endpoint: config.Endpoint,
|
|
|
|
blockNumber: nil,
|
|
|
|
blockHash: common.BytesToHash([]byte{}),
|
|
|
|
depositContractAddress: config.DepositContract,
|
2019-01-28 11:59:37 +00:00
|
|
|
chainStartFeed: new(event.Feed),
|
2019-01-17 15:14:32 +00:00
|
|
|
client: config.Client,
|
|
|
|
reader: config.Reader,
|
|
|
|
logger: config.Logger,
|
|
|
|
vrcCaller: vrcCaller,
|
2019-02-03 22:44:48 +00:00
|
|
|
chainStartDeposits: []*pb.Deposit{},
|
2019-02-05 17:25:09 +00:00
|
|
|
beaconDB: config.BeaconDB,
|
2018-07-14 19:48:42 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a web3 service's main event loop.
|
|
|
|
func (w *Web3Service) Start() {
|
2018-07-21 17:51:18 +00:00
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"endpoint": w.endpoint,
|
2018-07-28 19:53:02 +00:00
|
|
|
}).Info("Starting service")
|
2018-08-07 17:56:28 +00:00
|
|
|
go w.run(w.ctx.Done())
|
2018-07-14 19:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop the web3 service's main event loop and associated goroutines.
|
|
|
|
func (w *Web3Service) Stop() error {
|
|
|
|
defer w.cancel()
|
|
|
|
defer close(w.headerChan)
|
2018-07-28 19:53:02 +00:00
|
|
|
log.Info("Stopping service")
|
2018-07-14 19:48:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-28 11:59:37 +00:00
|
|
|
// ChainStartFeed returns a feed that is written to
|
|
|
|
// whenever the deposit contract fires a ChainStart log.
|
|
|
|
func (w *Web3Service) ChainStartFeed() *event.Feed {
|
|
|
|
return w.chainStartFeed
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:44:48 +00:00
|
|
|
// ChainStartDeposits returns a slice of validator deposits processed
|
|
|
|
// by the deposit contract and cached in the powchain service.
|
|
|
|
func (w *Web3Service) ChainStartDeposits() []*pb.Deposit {
|
|
|
|
return w.chainStartDeposits
|
|
|
|
}
|
|
|
|
|
2018-12-30 21:20:43 +00:00
|
|
|
// Status always returns nil.
|
|
|
|
// TODO(1204): Add service health checks.
|
|
|
|
func (w *Web3Service) Status() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:28:53 +00:00
|
|
|
// LatestBlockNumber in the ETH1.0 chain.
|
|
|
|
func (w *Web3Service) LatestBlockNumber() *big.Int {
|
|
|
|
return w.blockNumber
|
|
|
|
}
|
2019-01-16 14:01:21 +00:00
|
|
|
|
2019-01-30 12:28:53 +00:00
|
|
|
// LatestBlockHash in the ETH1.0 chain.
|
|
|
|
func (w *Web3Service) LatestBlockHash() common.Hash {
|
|
|
|
return w.blockHash
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 12:28:53 +00:00
|
|
|
// Client for interacting with the ETH1.0 chain.
|
|
|
|
func (w *Web3Service) Client() Client {
|
|
|
|
return w.client
|
|
|
|
}
|
2019-01-16 14:01:21 +00:00
|
|
|
|
2019-01-30 12:28:53 +00:00
|
|
|
// HasChainStartLogOccurred queries all logs in the deposit contract to verify
|
|
|
|
// if ChainStart has occurred. If so, it returns true alongside the ChainStart timestamp.
|
2019-02-03 22:44:48 +00:00
|
|
|
func (w *Web3Service) HasChainStartLogOccurred() (bool, uint64, error) {
|
2018-07-19 16:31:50 +00:00
|
|
|
query := ethereum.FilterQuery{
|
|
|
|
Addresses: []common.Address{
|
2019-01-17 15:14:32 +00:00
|
|
|
w.depositContractAddress,
|
2018-07-19 16:31:50 +00:00
|
|
|
},
|
|
|
|
}
|
2019-01-30 12:28:53 +00:00
|
|
|
logs, err := w.logger.FilterLogs(w.ctx, query)
|
2018-07-19 16:31:50 +00:00
|
|
|
if err != nil {
|
2019-02-03 22:44:48 +00:00
|
|
|
return false, 0, fmt.Errorf("could not filter deposit contract logs: %v", err)
|
2018-07-19 16:31:50 +00:00
|
|
|
}
|
2019-01-30 12:28:53 +00:00
|
|
|
for _, log := range logs {
|
|
|
|
if log.Topics[0] == hashutil.Hash(chainStartEventSignature) {
|
|
|
|
_, timestampData, err := contracts.UnpackChainStartLogData(log.Data)
|
|
|
|
if err != nil {
|
2019-02-03 22:44:48 +00:00
|
|
|
return false, 0, fmt.Errorf("unable to unpack ChainStart log data %v", err)
|
2019-01-30 12:28:53 +00:00
|
|
|
}
|
|
|
|
timestamp := binary.BigEndian.Uint64(timestampData)
|
|
|
|
if uint64(time.Now().Unix()) < timestamp {
|
2019-02-03 22:44:48 +00:00
|
|
|
return false, 0, fmt.Errorf(
|
2019-01-30 12:28:53 +00:00
|
|
|
"invalid timestamp from log expected %d > %d",
|
|
|
|
time.Now().Unix(),
|
|
|
|
timestamp,
|
|
|
|
)
|
|
|
|
}
|
2019-02-03 22:44:48 +00:00
|
|
|
return true, timestamp, nil
|
2018-07-19 16:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-03 22:44:48 +00:00
|
|
|
return false, 0, nil
|
2018-07-19 16:31:50 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 15:14:32 +00:00
|
|
|
// ProcessLog is the main method which handles the processing of all
|
2019-01-28 08:45:28 +00:00
|
|
|
// logs from the deposit contract on the ETH1.0 chain.
|
2019-01-17 15:14:32 +00:00
|
|
|
func (w *Web3Service) ProcessLog(VRClog gethTypes.Log) {
|
2019-01-16 14:01:21 +00:00
|
|
|
// Process logs according to their event signature.
|
|
|
|
if VRClog.Topics[0] == hashutil.Hash(depositEventSignature) {
|
2019-01-17 15:14:32 +00:00
|
|
|
w.ProcessDepositLog(VRClog)
|
2019-01-16 14:01:21 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if VRClog.Topics[0] == hashutil.Hash(chainStartEventSignature) {
|
2019-01-17 15:14:32 +00:00
|
|
|
w.ProcessChainStartLog(VRClog)
|
2019-01-16 14:01:21 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debugf("Log is not of a valid event signature %#x", VRClog.Topics[0])
|
|
|
|
}
|
|
|
|
|
2019-01-17 15:14:32 +00:00
|
|
|
// ProcessDepositLog processes the log which had been received from
|
2019-01-28 08:45:28 +00:00
|
|
|
// the ETH1.0 chain by trying to ascertain which participant deposited
|
2019-01-16 14:01:21 +00:00
|
|
|
// in the contract.
|
2019-01-17 15:14:32 +00:00
|
|
|
func (w *Web3Service) ProcessDepositLog(VRClog gethTypes.Log) {
|
2019-01-28 08:45:28 +00:00
|
|
|
merkleRoot, depositData, MerkleTreeIndex, err := contracts.UnpackDepositLogData(VRClog.Data)
|
2019-01-16 14:01:21 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Could not unpack log %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := w.saveInTrie(depositData, merkleRoot); err != nil {
|
|
|
|
log.Errorf("Could not save in trie %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
depositInput, err := blocks.DecodeDepositInput(depositData)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Could not decode deposit input %v", err)
|
|
|
|
return
|
|
|
|
}
|
2019-02-05 17:25:09 +00:00
|
|
|
deposit := &pb.Deposit{
|
|
|
|
DepositData: depositData,
|
|
|
|
}
|
2019-02-03 22:44:48 +00:00
|
|
|
if !w.chainStarted {
|
2019-02-05 17:25:09 +00:00
|
|
|
w.chainStartDeposits = append(w.chainStartDeposits, deposit)
|
|
|
|
} else {
|
|
|
|
w.beaconDB.InsertPendingDeposit(w.ctx, deposit, big.NewInt(int64(VRClog.BlockNumber)))
|
2019-02-03 22:44:48 +00:00
|
|
|
}
|
2019-01-16 14:01:21 +00:00
|
|
|
index := binary.BigEndian.Uint64(MerkleTreeIndex)
|
|
|
|
log.WithFields(logrus.Fields{
|
2019-02-05 14:07:42 +00:00
|
|
|
"publicKey": fmt.Sprintf("%#x", depositInput.Pubkey),
|
|
|
|
"merkleTreeIndex": index,
|
|
|
|
}).Info("Validator registered in deposit contract")
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 15:14:32 +00:00
|
|
|
// ProcessChainStartLog processes the log which had been received from
|
2019-01-28 08:45:28 +00:00
|
|
|
// the ETH1.0 chain by trying to determine when to start the beacon chain.
|
2019-01-17 15:14:32 +00:00
|
|
|
func (w *Web3Service) ProcessChainStartLog(VRClog gethTypes.Log) {
|
2019-01-28 08:45:28 +00:00
|
|
|
receiptRoot, timestampData, err := contracts.UnpackChainStartLogData(VRClog.Data)
|
2019-01-16 14:01:21 +00:00
|
|
|
if err != nil {
|
2019-01-17 15:14:32 +00:00
|
|
|
log.Errorf("Unable to unpack ChainStart log data %v", err)
|
|
|
|
return
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
2019-01-17 15:14:32 +00:00
|
|
|
if w.depositTrie.Root() != receiptRoot {
|
2019-01-28 08:45:28 +00:00
|
|
|
log.Errorf("Receipt root from log doesn't match the root saved in memory,"+
|
|
|
|
" want %#x but got %#x", w.depositTrie.Root(), receiptRoot)
|
2019-01-17 15:14:32 +00:00
|
|
|
return
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 15:14:32 +00:00
|
|
|
timestamp := binary.BigEndian.Uint64(timestampData)
|
|
|
|
if uint64(time.Now().Unix()) < timestamp {
|
|
|
|
log.Errorf("Invalid timestamp from log expected %d > %d", time.Now().Unix(), timestamp)
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
2019-02-03 22:44:48 +00:00
|
|
|
w.chainStarted = true
|
2019-01-17 15:14:32 +00:00
|
|
|
chainStartTime := time.Unix(int64(timestamp), 0)
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"ChainStartTime": chainStartTime,
|
|
|
|
}).Info("Minimum Number of Validators Reached for beacon-chain to start")
|
2019-01-28 11:59:37 +00:00
|
|
|
w.chainStartFeed.Send(chainStartTime)
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 12:28:53 +00:00
|
|
|
// run subscribes to all the services for the ETH1.0 chain.
|
|
|
|
func (w *Web3Service) run(done <-chan struct{}) {
|
|
|
|
if err := w.initDataFromVRC(); err != nil {
|
|
|
|
log.Errorf("Unable to retrieve data from VRC %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
headSub, err := w.reader.SubscribeNewHead(w.ctx, w.headerChan)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Unable to subscribe to incoming ETH1.0 chain headers: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
query := ethereum.FilterQuery{
|
|
|
|
Addresses: []common.Address{
|
|
|
|
w.depositContractAddress,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
logSub, err := w.logger.SubscribeFilterLogs(w.ctx, query, w.logChan)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Unable to query logs from VRC: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := w.processPastLogs(query); err != nil {
|
|
|
|
log.Errorf("Unable to process past logs %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer logSub.Unsubscribe()
|
|
|
|
defer headSub.Unsubscribe()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
log.Debug("ETH1.0 chain service context closed, exiting goroutine")
|
|
|
|
return
|
|
|
|
case <-headSub.Err():
|
|
|
|
log.Debug("Unsubscribed to head events, exiting goroutine")
|
|
|
|
return
|
|
|
|
case <-logSub.Err():
|
|
|
|
log.Debug("Unsubscribed to log events, exiting goroutine")
|
|
|
|
return
|
|
|
|
case header := <-w.headerChan:
|
|
|
|
w.blockNumber = header.Number
|
|
|
|
w.blockHash = header.Hash()
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"blockNumber": w.blockNumber,
|
|
|
|
"blockHash": w.blockHash.Hex(),
|
|
|
|
}).Debug("Latest web3 chain event")
|
|
|
|
case VRClog := <-w.logChan:
|
|
|
|
log.Info("Received deposit contract log")
|
|
|
|
w.ProcessLog(VRClog)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// initDataFromVRC calls the vrc contract and finds the deposit count
|
|
|
|
// and deposit root.
|
|
|
|
func (w *Web3Service) initDataFromVRC() error {
|
|
|
|
root, err := w.vrcCaller.GetDepositRoot(&bind.CallOpts{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not retrieve deposit root %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w.depositRoot = root[:]
|
2019-01-31 02:53:58 +00:00
|
|
|
w.depositTrie = trieutil.NewDepositTrie()
|
2019-01-30 12:28:53 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-16 14:01:21 +00:00
|
|
|
// saveInTrie saves in the in-memory deposit trie.
|
|
|
|
func (w *Web3Service) saveInTrie(depositData []byte, merkleRoot common.Hash) error {
|
|
|
|
if w.depositTrie.Root() != merkleRoot {
|
|
|
|
return errors.New("saved root in trie is unequal to root received from log")
|
|
|
|
}
|
|
|
|
|
|
|
|
w.depositTrie.UpdateDepositTrie(depositData)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-17 15:14:32 +00:00
|
|
|
// processPastLogs processes all the past logs from the deposit contract and
|
|
|
|
// updates the deposit trie with the data from each individual log.
|
2019-01-16 14:01:21 +00:00
|
|
|
func (w *Web3Service) processPastLogs(query ethereum.FilterQuery) error {
|
|
|
|
logs, err := w.logger.FilterLogs(w.ctx, query)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, log := range logs {
|
2019-01-17 15:14:32 +00:00
|
|
|
w.ProcessLog(log)
|
2019-01-16 14:01:21 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|