Skip to content

Commit

Permalink
Add tx aggregator server
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalodner committed May 1, 2020
1 parent a1b505c commit 9743d97
Show file tree
Hide file tree
Showing 24 changed files with 1,420 additions and 966 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/migrations/*.js
packages/arb-bridge-eth/test/**/*.js
packages/arb-provider-ethers/src/lib/abi/*
**/dist/main.js
**/node_modules/**
20 changes: 20 additions & 0 deletions packages/arb-provider-ethers/src/lib/abi/txaggregator.server.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Code generated by protoc-gen-tstypes. DO NOT EDIT.

declare namespace txaggregator {
export interface SendTransactionArgs {
to?: string
sequenceNum?: string
value?: string
data?: string
pubkey?: string
signature?: string
}

export interface SendTransactionReply {
accepted?: boolean
}

export interface TxAggregatorService {
SendTransaction: (r: SendTransactionArgs) => SendTransactionReply
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Code generated by protoc-gen-tstypes. DO NOT EDIT.

declare namespace validatorserver {
export interface LogInfo {
address?: string
blockHash?: string
blockNumber?: string
data?: string
logIndex?: string
topics?: Array<string>
transactionIndex?: string
transactionHash?: string
}

export interface FindLogsArgs {
fromHeight?: string
toHeight?: string
address?: string
topics?: Array<string>
}

export interface FindLogsReply {
logs?: Array<LogInfo>
}

export interface GetMessageResultArgs {
txHash?: string
}

export interface GetMessageResultReply {
found?: boolean
rawVal?: string
logPreHash?: string
logPostHash?: string
logValHashes?: Array<string>
onChainTxHash?: string
}

export interface GetAssertionCountArgs {}

export interface GetAssertionCountReply {
assertionCount?: number
}

export interface GetVMInfoArgs {}

export interface GetVMInfoReply {
vmID?: string
}

export interface CallMessageArgs {
contractAddress?: string
sender?: string
data?: string
}

export interface CallMessageReply {
rawVal?: string
}

export interface RollupValidatorService {
GetMessageResult: (r: GetMessageResultArgs) => GetMessageResultReply
CallMessage: (r: CallMessageArgs) => CallMessageReply
FindLogs: (r: FindLogsArgs) => FindLogsReply
GetAssertionCount: (r: GetAssertionCountArgs) => GetAssertionCountReply
GetVMInfo: (r: GetVMInfoArgs) => GetVMInfoReply
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2020, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"context"
"flag"
"log"
"os"

"github.com/gorilla/rpc"
"github.com/gorilla/rpc/json"

"github.com/ethereum/go-ethereum/ethclient"

"github.com/offchainlabs/arbitrum/packages/arb-util/common"
"github.com/offchainlabs/arbitrum/packages/arb-validator-core/arbbridge"
"github.com/offchainlabs/arbitrum/packages/arb-validator-core/ethbridge"
"github.com/offchainlabs/arbitrum/packages/arb-validator-core/utils"
"github.com/offchainlabs/arbitrum/packages/arb-validator/txaggregator"
)

func main() {
fs := flag.NewFlagSet("", flag.ContinueOnError)
walletArgs := utils.AddFlags(fs)

err := fs.Parse(os.Args[1:])
if err != nil {
log.Fatal(err)
}

if fs.NArg() != 3 {
log.Fatalf("usage: arb-tx-aggregator [--password=pass] [--gasprice==FloatInGwei] %v", utils.RollupArgsString)
}

rollupArgs := utils.ParseRollupCommand(fs, 0)

auth, err := utils.GetKeystore(rollupArgs.ValidatorFolder, walletArgs, fs)
if err != nil {
log.Fatal(err)
}

ethclint, err := ethclient.Dial(rollupArgs.EthURL)
if err != nil {
log.Fatal(err)
}
client := ethbridge.NewEthAuthClient(ethclint, auth)

if err := arbbridge.WaitForNonZeroBalance(context.Background(), client, common.NewAddressFromEth(auth.From)); err != nil {
log.Fatal(err)
}

rollupContract, err := client.NewRollupWatcher(rollupArgs.Address)
if err != nil {
log.Fatal(err)
}
inboxAddress, err := rollupContract.InboxAddress(context.Background())
if err != nil {
log.Fatal(err)
}
globalInbox, err := client.NewGlobalInbox(inboxAddress)
if err != nil {
log.Fatal(err)
}

server := txaggregator.NewRPCServer(context.Background(), globalInbox, rollupArgs.Address)

s := rpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json")
s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")

if err := s.RegisterService(server, "TxAggregator"); err != nil {
log.Fatal(err)
}

log.Fatal(utils.LaunchRPC(s, "1237"))
}
27 changes: 27 additions & 0 deletions packages/arb-tx-aggregator/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module github.com/offchainlabs/arbitrum/packages/arb-validator

go 1.12

require (
github.com/ethereum/go-ethereum v1.9.10
github.com/gogo/protobuf v1.1.1
github.com/golang/protobuf v1.3.2
github.com/gorilla/handlers v1.4.2
github.com/gorilla/mux v1.7.4
github.com/gorilla/rpc v1.2.0
github.com/offchainlabs/arbitrum/packages/arb-avm-cpp v0.4.3
github.com/offchainlabs/arbitrum/packages/arb-avm-go v0.4.3
github.com/offchainlabs/arbitrum/packages/arb-util v0.4.3
github.com/offchainlabs/arbitrum/packages/arb-validator-core v0.4.3
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
google.golang.org/grpc v1.23.1
)

replace github.com/offchainlabs/arbitrum/packages/arb-avm-go => ../arb-avm-go

replace github.com/offchainlabs/arbitrum/packages/arb-avm-cpp => ../arb-avm-cpp

replace github.com/offchainlabs/arbitrum/packages/arb-util => ../arb-util

replace github.com/offchainlabs/arbitrum/packages/arb-validator-core => ../arb-validator-core
Loading

0 comments on commit 9743d97

Please sign in to comment.