Skip to content

Commit

Permalink
Merge branch 'master' into trace-state-and-auto-redeems
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Apr 13, 2022
2 parents 832efa3 + a961c89 commit 6b0cc4c
Show file tree
Hide file tree
Showing 41 changed files with 321 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ target/
yarn-error.log
das/dasrpc/wireFormat.pb.go
das/dasrpc/wireFormat_grpc.pb.go

local/
10 changes: 10 additions & 0 deletions arbnode/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ func (a *BlockValidatorAPI) RevalidateBlock(ctx context.Context, blockNum rpc.Bl
}
return a.val.ValidateBlock(ctx, header, moduleRoot)
}

func (a *BlockValidatorAPI) LatestValidatedBlock(ctx context.Context) (uint64, error) {
block := a.val.LastBlockValidated()
return block, nil
}

func (a *BlockValidatorAPI) LatestValidatedBlockHash(ctx context.Context) (common.Hash, error) {
_, hash := a.val.LastBlockValidatedAndHash()
return hash, nil
}
9 changes: 9 additions & 0 deletions arbnode/arb_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type TransactionPublisher interface {
type ArbInterface struct {
txStreamer *TransactionStreamer
txPublisher TransactionPublisher
arbNode *Node
}

func NewArbInterface(txStreamer *TransactionStreamer, txPublisher TransactionPublisher) (*ArbInterface, error) {
Expand All @@ -29,6 +30,10 @@ func NewArbInterface(txStreamer *TransactionStreamer, txPublisher TransactionPub
}, nil
}

func (a *ArbInterface) Initialize(n *Node) {
a.arbNode = n
}

func (a *ArbInterface) PublishTransaction(ctx context.Context, tx *types.Transaction) error {
return a.txPublisher.PublishTransaction(ctx, tx)
}
Expand All @@ -40,3 +45,7 @@ func (a *ArbInterface) TransactionStreamer() *TransactionStreamer {
func (a *ArbInterface) BlockChain() *core.BlockChain {
return a.txStreamer.bc
}

func (a *ArbInterface) ArbNode() interface{} {
return a.arbNode
}
4 changes: 2 additions & 2 deletions arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ func TestTransactionStreamer(t *testing.T) {
}
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
67 changes: 62 additions & 5 deletions arbnode/node-interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/arbitrum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
Expand All @@ -23,10 +24,12 @@ import (
"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/solgen/go/node_interfacegen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/merkletree"
"github.com/offchainlabs/nitro/validator"
)

type Message = types.Message
Expand All @@ -48,6 +51,7 @@ func ApplyNodeInterface(

estimateMethod := nodeInterface.Methods["estimateRetryableTicket"]
outboxMethod := nodeInterface.Methods["constructOutboxProof"]
findBatchMethod := nodeInterface.Methods["findBatchContainingBlock"]

calldata := msg.Data()
if len(calldata) < 4 {
Expand Down Expand Up @@ -95,9 +99,7 @@ func ApplyNodeInterface(
// ArbitrumSubmitRetryableTx is unsigned so the following won't panic
msg, err := types.NewTx(submitTx).AsMessage(types.NewArbitrumSigner(nil), nil)
return msg, nil, err
}

if bytes.Equal(outboxMethod.ID, calldata[:4]) {
} else if bytes.Equal(outboxMethod.ID, calldata[:4]) {
inputs, err := outboxMethod.Inputs.Unpack(calldata[4:])
if err != nil {
return msg, nil, err
Expand All @@ -109,10 +111,31 @@ func ApplyNodeInterface(
return msg, nil, fmt.Errorf("leaf %v is newer than root of size %v", leaf, size)
}

method := nodeInterface.Methods["constructOutboxProof"]
res, err := nodeInterfaceConstructOutboxProof(msg, ctx, size, leaf, backend, method)
res, err := nodeInterfaceConstructOutboxProof(msg, ctx, size, leaf, backend, outboxMethod)
return msg, res, err
} else if bytes.Equal(findBatchMethod.ID, calldata[:4]) {
inputs, err := findBatchMethod.Inputs.Unpack(calldata[4:])
if err != nil {
return msg, nil, err
}
block, _ := inputs[0].(uint64)

batch, err := nodeInterfaceFindBatchContainingBlock(ctx, backend, block)
if err != nil {
return msg, nil, err
}
returnData, err := findBatchMethod.Outputs.Pack(batch)
if err != nil {
return msg, nil, fmt.Errorf("internal error: failed to encode outputs: %w", err)
}

res := &ExecutionResult{
UsedGas: 0,
Err: nil,
ReturnData: returnData,
ScheduledTxes: nil,
}
return msg, res, err
}

return msg, nil, errors.New("method does not exist in NodeInterface.sol")
Expand Down Expand Up @@ -393,6 +416,40 @@ func nodeInterfaceConstructOutboxProof(
return result, nil
}

func nodeInterfaceFindBatchContainingBlock(ctx context.Context, backend core.NodeInterfaceBackendAPI, block uint64) (uint64, error) {
apiBackend, ok := backend.(*arbitrum.APIBackend)
if !ok {
return 0, errors.New("API backend isn't Arbitrum")
}
arbNode, ok := apiBackend.GetArbitrumNode().(*Node)
if !ok {
return 0, errors.New("failed to get Arbitrum Node from backend")
}
genesis, err := arbNode.TxStreamer.GetGenesisBlockNumber()
if err != nil {
return 0, err
}
if block <= genesis {
return 0, fmt.Errorf("block %v is part of genesis", block)
}
pos := arbutil.BlockNumberToMessageCount(block, genesis) - 1
high, err := arbNode.InboxTracker.GetBatchCount()
if err != nil {
return 0, err
}
high--
latestCount, err := arbNode.InboxTracker.GetBatchMessageCount(high)
if err != nil {
return 0, err
}
latestBlock := arbutil.MessageCountToBlockNumber(latestCount, genesis)
if int64(block) > latestBlock {
return 0, fmt.Errorf("requested block %v is after latest on-chain block %v published in batch %v", block, latestBlock, high)
}

return validator.FindBatchContainingMessageIndex(arbNode.InboxTracker, pos, high)
}

func init() {
nodeInterface, err := abi.JSON(strings.NewReader(node_interfacegen.NodeInterfaceABI))
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,12 @@ func CreateNode(stack *node.Node, chainDb ethdb.Database, config *Config, l2Bloc
}

func (n *Node) Start(ctx context.Context) error {
err := n.TxPublisher.Initialize(ctx)
n.ArbInterface.Initialize(n)
err := n.Backend.Start()
if err != nil {
return err
}
err = n.TxPublisher.Initialize(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -766,6 +771,9 @@ func (n *Node) StopAndWait() {
}
n.TxStreamer.StopAndWait()
n.ArbInterface.BlockChain().Stop()
if err := n.Backend.Stop(); err != nil {
log.Error("backend stop", "err", err)
}
}

func CreateDefaultStack() (*node.Node, error) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/addressSet/addressSet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func size(t *testing.T, aset *AddressSet) uint64 {
return size
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/addressTable/addressTable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func size(t *testing.T, atab *AddressTable) uint64 {
return size
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/arbosState/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/offchainlabs/nitro/util/testhelpers"
)

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/blockhash/blockhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func TestBlockhash(t *testing.T) {

}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/blsTable/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func TestLegacyBLS(t *testing.T) {
}
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/offchainlabs/nitro/util/testhelpers"
)

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion arbos/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func InternalTxStartBlock(
}
return &types.ArbitrumInternalTx{
ChainId: chainId,
Type: arbInternalTxStartBlock,
SubType: arbInternalTxStartBlock,
Data: data,
L2BlockNumber: l2BlockNum,
}
Expand Down
4 changes: 2 additions & 2 deletions arbos/l1pricing/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/offchainlabs/nitro/util/testhelpers"
)

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbos/l2pricing/l2pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ func rateEstimate(t *testing.T, pricing *L2PricingState) uint64 {
return value
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions arbstate/geth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func RunMessagesThroughAPI(t *testing.T, msgs [][]byte, statedb *state.StateDB)
}
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion blockscout
Submodule blockscout updated 0 files
7 changes: 4 additions & 3 deletions blsSignatures/blsSignatures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package blsSignatures

import (
"github.com/offchainlabs/nitro/util/testhelpers"
"testing"

"github.com/offchainlabs/nitro/util/testhelpers"
)

func TestValidSignature(t *testing.T) {
Expand Down Expand Up @@ -106,9 +107,9 @@ func TestSignatureAggregationDifferentMessages(t *testing.T) {
}
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions broadcaster/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func TestBroadcasterMessagesRemovedOnConfirmation(t *testing.T) {

}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
12 changes: 12 additions & 0 deletions contracts/src/mocks/Simple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ pragma solidity ^0.8.0;
contract Simple {
uint64 public counter;

event CounterEvent(uint64 count);
event NullEvent();

function increment() external {
counter++;
}

function incrementEmit() external {
counter++;
emit CounterEvent(counter);
}

function emitNullEvent() external {
emit NullEvent();
}

function checkBlockHashes() external view returns (uint256) {
require(blockhash(block.number - 1) != blockhash(block.number - 2), "SAME_BLOCK_HASH");
return block.number;
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/node-interface/NodeInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ interface NodeInterface {
bytes32 root,
bytes32[] memory proof
);

/**
* @notice Finds the L1 batch containing a requested L2 block, reverting if none does
* @param block The L2 block being queried
* @return batch The L1 block containing the requested L2 block
*/
function findBatchContainingBlock(uint64 block) external view returns (uint64 batch);
}
4 changes: 2 additions & 2 deletions das/das_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func TestDASMissingMessage(t *testing.T) {
}
}

func Require(t *testing.T, err error, text ...string) {
func Require(t *testing.T, err error, printables ...interface{}) {
t.Helper()
testhelpers.RequireImpl(t, err, text...)
testhelpers.RequireImpl(t, err, printables...)
}

func Fail(t *testing.T, printables ...interface{}) {
Expand Down
Loading

0 comments on commit 6b0cc4c

Please sign in to comment.