Skip to content

Commit

Permalink
Merge pull request #557 from OffchainLabs/develop
Browse files Browse the repository at this point in the history
Update to v0.7.1
  • Loading branch information
edfelten authored Sep 4, 2020
2 parents c1e1444 + 0f6c435 commit 69c299b
Show file tree
Hide file tree
Showing 47 changed files with 560 additions and 359 deletions.
2 changes: 1 addition & 1 deletion docs/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Here are the important dependencies in case you are not running on a supported O
Download the Arbitrum Monorepo from source:

```bash
git clone -b v0.7.0 https://github.com/offchainlabs/arbitrum.git
git clone -b v0.7.1 https://github.com/offchainlabs/arbitrum.git
cd arbitrum
yarn
yarn build
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-avm-cpp/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ int main(int argc, char* argv[]) {
}
}

auto assertion =
mach.run(100000000, std::move(inbox_messages), std::chrono::seconds(0));
auto assertion = mach.run(10000000000000, std::move(inbox_messages),
std::chrono::seconds(0));

std::cout << "Produced " << assertion.logs.size() << " logs\n";

Expand Down
2 changes: 1 addition & 1 deletion packages/arb-avm-cpp/cmachine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (m *Machine) ExecuteCallServerAssertion(
func (m *Machine) ExecuteSideloadedAssertion(
maxSteps uint64,
inboxMessages []inbox.InboxMessage,
sideloadValue value.TupleValue,
sideloadValue *value.TupleValue,
maxWallTime time.Duration,
) (*protocol.ExecutionAssertion, uint64) {
msgDataC := C.CBytes(encodeInboxMessages(inboxMessages))
Expand Down
25 changes: 19 additions & 6 deletions packages/arb-avm-cpp/data_storage/src/value/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,25 @@ DeleteResults deleteMachine(Transaction& transaction, uint256_t machine_hash) {

deleteCode(transaction, segment_counts);

if (!(delete_static_res.status.ok() &&
delete_register_res.status.ok() &&
delete_datastack_res.status.ok() &&
delete_auxstack_res.status.ok() &&
delete_staged_message_res.status.ok())) {
std::cout << "error deleting checkpoint" << std::endl;
if (!delete_static_res.status.ok()) {
std::cout << "error deleting static in checkpoint" << std::endl;
}

if (!delete_register_res.status.ok()) {
std::cout << "error deleting register in checkpoint" << std::endl;
}

if (!delete_datastack_res.status.ok()) {
std::cout << "error deleting datastack in checkpoint" << std::endl;
}

if (!delete_auxstack_res.status.ok()) {
std::cout << "error deleting auxstack in checkpoint" << std::endl;
}

if (!delete_staged_message_res.status.ok()) {
std::cout << "error deleting staged message in checkpoint"
<< std::endl;
}
}
return delete_results;
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-avm-cpp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/ethereum/go-ethereum v1.9.20
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.1
)

replace github.com/offchainlabs/arbitrum/packages/arb-util => ../arb-util
3 changes: 2 additions & 1 deletion packages/arb-bridge-eth/scripts/launch-geth
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ docker run -d -it --rm -p 7545:7545 -p 7546:7546 \
--rpc --rpcaddr 0.0.0.0 --rpcport 7545 --rpccorsdomain="*" --rpcvhosts=* \
--rpcapi 'personal,db,eth,net,web3,txpool,miner' \
--ws --wsaddr 0.0.0.0 --wsport 7546 --wsorigins '*' \
--wsapi personal,admin,db,eth,net,web3,miner,shh,txpool,debug
--wsapi personal,admin,db,eth,net,web3,miner,shh,txpool,debug \
--gcmode=archive
while ! nc -z localhost 7545; do sleep 2; done;
echo "Finished waiting for geth on localhost:7545..."
yarn buidler deploy --network parity --export bridge_eth_addresses.json && [ -f bridge_eth_addresses.json ]
Expand Down
6 changes: 3 additions & 3 deletions packages/arb-checkpointer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.13

require (
github.com/golang/protobuf v1.4.2
github.com/offchainlabs/arbitrum/packages/arb-avm-cpp v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-validator-core v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-avm-cpp v0.7.1
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.1
github.com/offchainlabs/arbitrum/packages/arb-validator-core v0.7.1
google.golang.org/protobuf v1.25.0
)

Expand Down
6 changes: 3 additions & 3 deletions packages/arb-evm/evm/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (l Log) String() string {
}

func NewLogFromValue(val value.Value) (Log, error) {
tupVal, ok := val.(value.TupleValue)
tupVal, ok := val.(*value.TupleValue)
if !ok {
return Log{}, errors.New("log must be a tuple")
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func NewLogFromValue(val value.Value) (Log, error) {
return Log{address, topics, logData}, nil
}

func (l Log) AsValue() value.TupleValue {
func (l Log) AsValue() *value.TupleValue {
data := []value.Value{
value.NewValueFromAddress(l.Address),
inbox.BytesToByteStack(l.Data),
Expand Down Expand Up @@ -177,7 +177,7 @@ func LogStackToLogs(val value.Value) ([]Log, error) {
return logs, nil
}

func LogsToLogStack(logs []Log) value.TupleValue {
func LogsToLogStack(logs []Log) *value.TupleValue {
logValues := make([]value.Value, 0, len(logs))
for i := range logs {
logValues = append(logValues, logs[len(logs)-1-i].AsValue())
Expand Down
10 changes: 5 additions & 5 deletions packages/arb-evm/evm/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,22 @@ func (r *TxResult) ToEthReceipt(blockHash common.Hash) *types.Receipt {
}

func parseTxResult(l1MsgVal value.Value, resultInfo value.Value, gasInfo value.Value, chainInfo value.Value) (*TxResult, error) {
resultTup, ok := resultInfo.(value.TupleValue)
resultTup, ok := resultInfo.(*value.TupleValue)
if !ok || resultTup.Len() != 3 {
return nil, fmt.Errorf("advise expected result info tuple of length 3, but recieved %v", resultTup)
}
resultCode, _ := resultTup.GetByInt64(0)
returnData, _ := resultTup.GetByInt64(1)
evmLogs, _ := resultTup.GetByInt64(2)

gasInfoTup, ok := gasInfo.(value.TupleValue)
gasInfoTup, ok := gasInfo.(*value.TupleValue)
if !ok || gasInfoTup.Len() != 2 {
return nil, fmt.Errorf("advise expected gas info tuple of length 2, but recieved %v", gasInfoTup)
}
gasUsed, _ := gasInfoTup.GetByInt64(0)
gasPrice, _ := gasInfoTup.GetByInt64(1)

chainInfoTup, ok := chainInfo.(value.TupleValue)
chainInfoTup, ok := chainInfo.(*value.TupleValue)
if !ok || chainInfoTup.Len() != 3 {
return nil, fmt.Errorf("advise expected tx block data tuple of length 3, but recieved %v", resultTup)
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func parseBlockResult(blockNum value.Value, timestamp value.Value, gasLimit valu
}

func parseOutputStatistics(val value.Value) (*OutputStatistics, error) {
tup, ok := val.(value.TupleValue)
tup, ok := val.(*value.TupleValue)
if !ok || tup.Len() != 5 {
return nil, errors.New("expected result to be nonempty tuple")
}
Expand Down Expand Up @@ -397,7 +397,7 @@ func parseOutputStatistics(val value.Value) (*OutputStatistics, error) {
}

func NewResultFromValue(val value.Value) (Result, error) {
tup, ok := val.(value.TupleValue)
tup, ok := val.(*value.TupleValue)
if !ok || tup.Len() == 0 {
return nil, errors.New("expected result to be nonempty tuple")
}
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-evm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.13
require (
github.com/ethereum/go-ethereum v1.9.20
github.com/golang/protobuf v1.4.2
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-validator-core v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.1
github.com/offchainlabs/arbitrum/packages/arb-validator-core v0.7.1
github.com/pkg/errors v0.9.1
google.golang.org/protobuf v1.25.0
)
Expand Down
6 changes: 3 additions & 3 deletions packages/arb-evm/message/l2Message.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ func (t ContractTransaction) AsData() ([]byte, error) {

func (t ContractTransaction) AsDataSafe() []byte {
ret := make([]byte, 0)
ret = append(ret, math.U256Bytes(t.MaxGas)...)
ret = append(ret, math.U256Bytes(t.GasPriceBid)...)
ret = append(ret, math.U256Bytes(new(big.Int).Set(t.MaxGas))...)
ret = append(ret, math.U256Bytes(new(big.Int).Set(t.GasPriceBid))...)
ret = append(ret, addressData(t.DestAddress)...)
ret = append(ret, math.U256Bytes(t.Payment)...)
ret = append(ret, math.U256Bytes(new(big.Int).Set(t.Payment))...)
ret = append(ret, t.Data...)
return ret
}
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-evm/message/outMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewOutMessage(msg Message, sender common.Address) OutMessage {

func NewOutMessageFromValue(val value.Value) (OutMessage, error) {
failRet := OutMessage{}
tup, ok := val.(value.TupleValue)
tup, ok := val.(*value.TupleValue)
if !ok {
return failRet, errors.New("val must be a tuple")
}
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-provider-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.13
require (
github.com/ethereum/go-ethereum v1.9.20
github.com/gorilla/rpc v1.2.0
github.com/offchainlabs/arbitrum/packages/arb-evm v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.0
github.com/offchainlabs/arbitrum/packages/arb-evm v0.7.1
github.com/offchainlabs/arbitrum/packages/arb-util v0.7.1
github.com/pkg/errors v0.9.1
)

Expand Down
47 changes: 30 additions & 17 deletions packages/arb-tx-aggregator/batcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/offchainlabs/arbitrum/packages/arb-validator-core/ethutils"
)

const maxBatchSize ethcommon.StorageSize = 500000
const maxBatchSize ethcommon.StorageSize = 120000

type TransactionBatcher interface {
PendingTransactionCount(account common.Address) *uint64
Expand All @@ -54,6 +54,8 @@ type Batcher struct {
client ethutils.EthClient
globalInbox arbbridge.GlobalInbox

keepPendingState bool

db *txdb.TxDB

sync.Mutex
Expand All @@ -71,12 +73,14 @@ func NewBatcher(
client ethutils.EthClient,
globalInbox arbbridge.GlobalInbox,
maxBatchTime time.Duration,
keepPendingState bool,
) *Batcher {
signer := types.NewEIP155Signer(message.ChainAddressToID(rollupAddress))
server := &Batcher{
signer: signer,
client: client,
globalInbox: globalInbox,
keepPendingState: keepPendingState,
db: db,
valid: true,
queuedTxes: newTxQueues(),
Expand All @@ -86,7 +90,7 @@ func NewBatcher(

go func() {
lastBatch := time.Now()
ticker := time.NewTicker(time.Millisecond * 10)
ticker := time.NewTicker(time.Millisecond * 100)
defer ticker.Stop()
for {
select {
Expand All @@ -98,15 +102,18 @@ func NewBatcher(
for {
tx, accountIndex, cont := server.pendingBatch.popRandomTx(server.queuedTxes, signer)
if tx != nil {
newSnap := server.pendingBatch.snap.Clone()
server.Unlock()
newSnap, err := snapWithTx(newSnap, tx, signer)
server.Lock()
if err != nil {
log.Println("Aggregator ignored invalid tx", err)
continue
if keepPendingState {
newSnap := server.pendingBatch.snap.Clone()
server.Unlock()
newSnap, err := snapWithTx(newSnap, tx, signer)
server.Lock()
if err != nil {
log.Println("Aggregator ignored invalid tx", err)
continue
}
server.pendingBatch.updateSnap(newSnap)
}
server.pendingBatch.addUpdatedSnap(tx, newSnap)
server.pendingBatch.addIncludedTx(tx)
server.queuedTxes.maybeRemoveAccountAtIndex(accountIndex)
}
if server.pendingBatch.full || (!cont && time.Since(lastBatch) > maxBatchTime) {
Expand Down Expand Up @@ -148,6 +155,8 @@ func NewBatcher(
log.Fatal("Error submitted batch", err)
}

log.Println("Got receipt for batch in tx", receipt.TxHash.Hex(), "completed at block", receipt.BlockNumber, "using", receipt.GasUsed, "gas")

// batch succeeded
server.Lock()
server.pendingSentBatches.Remove(server.pendingSentBatches.Front())
Expand Down Expand Up @@ -194,6 +203,9 @@ func (m *Batcher) sendBatch(ctx context.Context) {
}

func (m *Batcher) PendingSnapshot() *snapshot.Snapshot {
if !m.keepPendingState {
return m.db.LatestSnapshot()
}
m.Lock()
defer m.Unlock()
m.setupPending()
Expand All @@ -214,14 +226,13 @@ func (m *Batcher) PendingTransactionCount(account common.Address) *uint64 {
// SendTransaction takes a request signed transaction l2message from a client
// and puts it in a queue to be included in the next transaction batch
func (m *Batcher) SendTransaction(tx *types.Transaction) (common.Hash, error) {
ethSender, err := types.Sender(m.signer, tx)
_, err := types.Sender(m.signer, tx)
if err != nil {
log.Println("Error processing transaction", err)
return common.Hash{}, err
}

txHash := common.NewHashFromEth(tx.Hash())
log.Println("Got tx: with hash", txHash, "from", ethSender.Hex())

m.Lock()
defer m.Unlock()
Expand All @@ -230,11 +241,13 @@ func (m *Batcher) SendTransaction(tx *types.Transaction) (common.Hash, error) {
return common.Hash{}, errors.New("tx aggregator is not running")
}

// Make sure we have an up to date batch to check against
m.setupPending()
if m.keepPendingState {
// Make sure we have an up to date batch to check against
m.setupPending()

if err := m.pendingBatch.checkValidForQueue(tx); err != nil {
return common.Hash{}, err
if err := m.pendingBatch.checkValidForQueue(tx); err != nil {
return common.Hash{}, err
}
}

if err := m.queuedTxes.addTransaction(tx, m.signer); err != nil {
Expand All @@ -245,7 +258,7 @@ func (m *Batcher) SendTransaction(tx *types.Transaction) (common.Hash, error) {
}

func (m *Batcher) setupPending() {
snap := m.db.LatestSnapshot()
snap := m.db.LatestSnapshot().Clone()
if m.pendingBatch.snap.Height().Cmp(snap.Height()) < 0 {
// Add all of the already broadcast transactions to the snapshot
// If they were already included, they'll be ignored because they will
Expand Down
11 changes: 8 additions & 3 deletions packages/arb-tx-aggregator/batcher/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package batcher
import (
"container/heap"
"errors"
"log"
"math/rand"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"

"github.com/offchainlabs/arbitrum/packages/arb-evm/message"
"github.com/offchainlabs/arbitrum/packages/arb-tx-aggregator/snapshot"
arbcommon "github.com/offchainlabs/arbitrum/packages/arb-util/common"
"log"
"math/rand"
)

// An TxHeap is a min-heap of transactions sorted by nonce.
Expand Down Expand Up @@ -219,8 +221,11 @@ func snapWithTx(snap *snapshot.Snapshot, tx *types.Transaction, signer types.Sig
return snap, err
}

func (p *pendingBatch) addUpdatedSnap(tx *types.Transaction, newSnap *snapshot.Snapshot) {
func (p *pendingBatch) updateSnap(newSnap *snapshot.Snapshot) {
p.snap = newSnap
}

func (p *pendingBatch) addIncludedTx(tx *types.Transaction) {
p.appliedTxes = append(p.appliedTxes, tx)
p.sizeBytes += tx.Size()
sender, _ := types.Sender(p.signer, tx)
Expand Down
Loading

0 comments on commit 69c299b

Please sign in to comment.