-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rianhughes/rpc8-getMessageStatus2
- Loading branch information
Showing
31 changed files
with
549 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.