Skip to content

Commit

Permalink
Merge branch 'main' into rianhughes/rpc8-getMessageStatus2
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes authored Oct 8, 2024
2 parents bcbcbd4 + 1786cb3 commit ecefefd
Show file tree
Hide file tree
Showing 31 changed files with 549 additions and 245 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ jobs:
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}

dev-starknet-go-tests:
needs: [validate_dev]
uses: ./.github/workflows/starknet-go-tests.yml
secrets:
TEST_RPC_URL: ${{ secrets.DEV_SEPOLIA_URL }}/v0_7

promote_to_staging:
needs: [build_docker_image, validate_dev]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -133,6 +139,12 @@ jobs:
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}

staging-starknet-go-tests:
needs: [promote_to_staging]
uses: ./.github/workflows/starknet-go-tests.yml
secrets:
TEST_RPC_URL: ${{ secrets.STAGING_SEPOLIA_URL }}/v0_7

promote_to_production:
needs: [build_docker_image, promote_to_staging]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -176,3 +188,9 @@ jobs:
TEST_RPC_URL: ${{ secrets.PROD_SEPOLIA_URL }}/v0_7
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.TEST_ACCOUNT_PRIVATE_KEY }}

prod-starknet-go-tests:
needs: [test_in_production]
uses: ./.github/workflows/starknet-go-tests.yml
secrets:
TEST_RPC_URL: ${{ secrets.PROD_SEPOLIA_URL }}/v0_7
4 changes: 2 additions & 2 deletions .github/workflows/find-smallest-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- .github/workflows/find-smallest-rust.yml
- core/rust/*
- vm/rust/*
- starknet/rust/*
- starknet/compiler/rust/*
workflow_dispatch:

concurrency:
Expand All @@ -24,7 +24,7 @@ jobs:
id: rust-version
uses: derrix060/detect-rust-minimum-version@v1
with:
paths: core/rust/,vm/rust/,starknet/rust/
paths: core/rust/,vm/rust/,starknet/compiler/rust/
- name: Send notification on PR
uses: actions/github-script@v7
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/juno-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
workspaces: |
vm/rust
core/rust
starknet/rust
starknet/compiler/rust
- name: Install deps
run: make install-deps
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/starknet-go-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: starknet-go tests

on:
workflow_call:
inputs:
ref:
description: 'The branch, tag or SHA to checkout'
required: false
default: 'v0.7.1'
type: string
secrets:
TEST_RPC_URL:
required: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
repository: NethermindEth/starknet.go
ref: ${{ inputs.ref }}

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Install dependencies
run: go mod download

- name: Test RPC on testnet
run: cd rpc && go test -timeout 1200s -v -env testnet .
env:
INTEGRATION_BASE: ${{ secrets.TEST_RPC_URL }}
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ core-rust:
$(MAKE) -C core/rust $(VM_TARGET)

compiler:
$(MAKE) -C starknet/rust $(VM_TARGET)
$(MAKE) -C starknet/compiler/rust $(VM_TARGET)

generate: ## generate
mkdir -p mocks
Expand Down Expand Up @@ -94,13 +94,13 @@ tidy: ## add missing and remove unused modules
format: ## run go & rust formatters
$(MAKE) -C vm/rust format
$(MAKE) -C core/rust format
$(MAKE) -C starknet/rust format
$(MAKE) -C starknet/compiler/rust format
gofumpt -l -w .

clean: ## clean project builds
$(MAKE) -C vm/rust clean
$(MAKE) -C core/rust clean
$(MAKE) -C starknet/rust clean
$(MAKE) -C starknet/compiler/rust clean
@rm -rf ./build

help: ## show this help
Expand All @@ -115,7 +115,6 @@ feedernode: juno-cached
--p2p-feeder-node \
--p2p-addr=/ip4/0.0.0.0/tcp/7777 \
--p2p-private-key="5f6cdc3aebcc74af494df054876100368ef6126e3a33fa65b90c765b381ffc37a0a63bbeeefab0740f24a6a38dabb513b9233254ad0020c721c23e69bc820089" \
--metrics-port=9090

node1: juno-cached
./build/juno \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Use the provided snapshots to quickly sync your Juno node with the current state
| ------- | ------------- |
| **>=v0.9.2** | [**juno_sepolia.tar**](https://juno-snapshots.nethermind.dev/files/sepolia/latest) |
## Sepolia-Integration
#### Sepolia-Integration
| Version | Download Link |
| ------- | ------------- |
Expand Down
3 changes: 2 additions & 1 deletion adapters/p2p2core/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/starknet/compiler"
"github.com/NethermindEth/juno/utils"
)

Expand Down Expand Up @@ -110,7 +111,7 @@ func createCompiledClass(cairo1 *spec.Cairo1Class) (*core.CompiledClass, error)
Version: cairo1.ContractClassVersion,
}

compiledClass, err := starknet.Compile(def)
compiledClass, err := compiler.Compile(def)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/block_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestTransactionCommitmentPoseidon(t *testing.T) {

c, err := transactionCommitmentPoseidon(txs)
require.NoError(t, err)
expected := utils.HexToFelt(t, "0x4ca6d4ceb367bf070d896a1479190d3c7b751f525e69a46ee2c83f0afe7cb8")
expected := utils.HexToFelt(t, "0x68303856fce63d62acb85da0766b370c03754aa316b0b5bce05982f9561b73d")
assert.Equal(t, expected, c, "expected: %s, got: %s", expected, c)
})
t.Run("txs without signature", func(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,10 @@ func transactionCommitmentPoseidon(transactions []Transaction) (*felt.Felt, erro
var digest crypto.PoseidonDigest
digest.Update(transaction.Hash())

switch transaction.(type) {
case *DeployTransaction, *L1HandlerTransaction:
if txSignature := transaction.Signature(); len(txSignature) > 0 {
digest.Update(txSignature...)
} else {
digest.Update(&felt.Zero)
default:
digest.Update(transaction.Signature()...)
}

return digest.Finish()
Expand Down
3 changes: 0 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ type Transaction interface {
// Get fetches the value for the given key, should return ErrKeyNotFound if key is not present
// Caller should not assume that the slice would stay valid after the call to cb
Get(key []byte, cb func([]byte) error) error

// Impl returns the underlying transaction object
Impl() any
}

// View : see db.DB.View
Expand Down
105 changes: 105 additions & 0 deletions db/pebble/batch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package pebble

import (
"errors"
"sync"
"time"

"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/utils"
"github.com/cockroachdb/pebble"
)

var _ db.Transaction = (*batch)(nil)

type batch struct {
batch *pebble.Batch
lock *sync.Mutex
listener db.EventListener
}

func NewBatch(dbBatch *pebble.Batch, lock *sync.Mutex, listener db.EventListener) *batch {
return &batch{
batch: dbBatch,
lock: lock,
listener: listener,
}
}

// Discard : see db.Transaction.Discard
func (b *batch) Discard() error {
if b.batch == nil {
return nil
}

err := b.batch.Close()
b.batch = nil
b.lock.Unlock()
b.lock = nil

return err
}

// Commit : see db.Transaction.Commit
func (b *batch) Commit() error {
if b.batch == nil {
return ErrDiscardedTransaction
}

start := time.Now()
defer func() { b.listener.OnCommit(time.Since(start)) }()
return utils.RunAndWrapOnError(b.Discard, b.batch.Commit(pebble.Sync))
}

// Set : see db.Transaction.Set
func (b *batch) Set(key, val []byte) error {
start := time.Now()
if len(key) == 0 {
return errors.New("empty key")
}

if b.batch == nil {
return ErrDiscardedTransaction
}

defer func() { b.listener.OnIO(true, time.Since(start)) }()

return b.batch.Set(key, val, pebble.Sync)
}

// Delete : see db.Transaction.Delete
func (b *batch) Delete(key []byte) error {
if b.batch == nil {
return ErrDiscardedTransaction
}

start := time.Now()
defer func() { b.listener.OnIO(true, time.Since(start)) }()

return b.batch.Delete(key, pebble.Sync)
}

// Get : see db.Transaction.Get
func (b *batch) Get(key []byte, cb func([]byte) error) error {
if b.batch == nil {
return ErrDiscardedTransaction
}
return get(b.batch, key, cb, b.listener)
}

// NewIterator : see db.Transaction.NewIterator
func (b *batch) NewIterator() (db.Iterator, error) {
var iter *pebble.Iterator
var err error

if b.batch == nil {
return nil, ErrDiscardedTransaction
}

iter, err = b.batch.NewIter(nil)
if err != nil {
return nil, err
}

return &iterator{iter: iter}, nil
}
34 changes: 34 additions & 0 deletions db/pebble/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pebble

import (
"errors"
"io"
"time"

"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/utils"
"github.com/cockroachdb/pebble"
)

type getter interface {
Get([]byte) ([]byte, io.Closer, error)
}

func get(g getter, key []byte, cb func([]byte) error, listener db.EventListener) error {
start := time.Now()
var val []byte
var closer io.Closer

val, closer, err := g.Get(key)

// We need it evaluated immediately so the duration doesn't include the runtime of the user callback that we call below.
defer listener.OnIO(false, time.Since(start)) //nolint:govet
if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return db.ErrKeyNotFound
}
return err
}

return utils.RunAndWrapOnError(closer.Close, cb(val))
}
16 changes: 8 additions & 8 deletions db/pebble/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pebble

import (
"context"
"errors"
"fmt"
"sync"
"testing"
Expand All @@ -18,6 +19,10 @@ const (
minCacheSizeMB = 8
)

var (
ErrDiscardedTransaction = errors.New("discarded transaction")
ErrReadOnlyTransaction = errors.New("read-only transaction")
)
var _ db.DB = (*DB)(nil)

type DB struct {
Expand Down Expand Up @@ -83,19 +88,14 @@ func (d *DB) WithListener(listener db.EventListener) db.DB {
}

// NewTransaction : see db.DB.NewTransaction
// Batch is used for read-write operations, while snapshot is used for read-only operations
func (d *DB) NewTransaction(update bool) (db.Transaction, error) {
txn := &Transaction{
listener: d.listener,
}
if update {
d.wMutex.Lock()
txn.lock = d.wMutex
txn.batch = d.pebble.NewIndexedBatch()
} else {
txn.snapshot = d.pebble.NewSnapshot()
return NewBatch(d.pebble.NewIndexedBatch(), d.wMutex, d.listener), nil
}

return txn, nil
return NewSnapshot(d.pebble.NewSnapshot(), d.listener), nil
}

// Close : see io.Closer.Close
Expand Down
2 changes: 1 addition & 1 deletion db/pebble/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func TestPanic(t *testing.T) {
require.ErrorIs(t, testDB.View(func(txn db.Transaction) error {
return txn.Get([]byte{0}, func(b []byte) error { return nil })
}), db.ErrKeyNotFound)
require.EqualError(t, panicingTxn.Get([]byte{0}, func(b []byte) error { return nil }), "discarded txn")
require.EqualError(t, panicingTxn.Get([]byte{0}, func(b []byte) error { return nil }), "discarded transaction")
}()

require.NoError(t, testDB.Update(func(txn db.Transaction) error {
Expand Down
Loading

0 comments on commit ecefefd

Please sign in to comment.