Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): Custom RPC types #1893

Draft
wants to merge 59 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0eec5fd
bet
itsdevbear Aug 14, 2024
d3907f4
bet
itsdevbear Aug 14, 2024
d828672
bet
itsdevbear Aug 14, 2024
17a7b79
bet
itsdevbear Aug 14, 2024
a2547f1
bet
itsdevbear Aug 14, 2024
4ca0c57
bet
itsdevbear Aug 14, 2024
39c3e7d
bet
itsdevbear Aug 14, 2024
441a038
bet
itsdevbear Aug 14, 2024
fe9fd58
bet
itsdevbear Aug 14, 2024
5f56fe7
bet
itsdevbear Aug 14, 2024
57a3bf3
bet
itsdevbear Aug 14, 2024
fbcf372
bet
itsdevbear Aug 14, 2024
85e1837
bet
itsdevbear Aug 14, 2024
cd8e51d
bet
itsdevbear Aug 14, 2024
799feb1
bet
itsdevbear Aug 14, 2024
569a674
bet
itsdevbear Aug 14, 2024
f1a2945
bet
itsdevbear Aug 14, 2024
92b3b45
bet
itsdevbear Aug 14, 2024
079fcdc
bet
itsdevbear Aug 14, 2024
31cf017
bet
itsdevbear Aug 15, 2024
cbfac1e
bet
itsdevbear Aug 15, 2024
18237a1
bet
itsdevbear Aug 15, 2024
9c7f44d
bet
itsdevbear Aug 15, 2024
fd90876
bet
itsdevbear Aug 15, 2024
59a20d0
bet
itsdevbear Aug 15, 2024
50b4f0e
Merge branch 'main' into custom-rpc-types
itsdevbear Aug 15, 2024
e919d88
bet
itsdevbear Aug 15, 2024
a767000
Merge branch 'main' into custom-rpc-types
itsdevbear Aug 15, 2024
3fc5350
bet
itsdevbear Aug 15, 2024
939f14b
bet
itsdevbear Aug 15, 2024
53a7ef1
bet
itsdevbear Aug 15, 2024
9f22f3d
bet
itsdevbear Aug 15, 2024
5d9ff65
bet
itsdevbear Aug 15, 2024
347c1d2
Merge branch 'main' into custom-rpc-types
itsdevbear Aug 15, 2024
72ae104
bet
itsdevbear Aug 15, 2024
d7ffc21
merge
itsdevbear Aug 15, 2024
248286c
bet
itsdevbear Aug 15, 2024
19306ce
bet
itsdevbear Aug 15, 2024
a264441
bet
itsdevbear Aug 15, 2024
3dc62f0
bet
itsdevbear Aug 15, 2024
fd0a805
bet
itsdevbear Aug 15, 2024
43799a4
bet
itsdevbear Aug 15, 2024
9b08e28
bet
itsdevbear Aug 15, 2024
af0c586
bet
itsdevbear Aug 15, 2024
9a8fdb4
bet
itsdevbear Aug 15, 2024
88b6899
bet
itsdevbear Aug 15, 2024
70a74c8
Merge branch 'main' into custom-rpc-types
itsdevbear Aug 15, 2024
d198db5
bet
itsdevbear Aug 15, 2024
257e8ba
Merge branch 'main' into custom-rpc-types
itsdevbear Aug 16, 2024
20f7634
Merge branch 'main' of github.com:berachain/beacon-kit into custom-rp…
calbera Oct 1, 2024
ab27640
log generic
calbera Oct 1, 2024
be73fd8
bet
calbera Oct 1, 2024
ce4ad41
Merge branch 'main' into custom-rpc-types
calbera Oct 1, 2024
8e30442
bet
calbera Oct 2, 2024
c528d7e
nits
calbera Oct 2, 2024
0a30dcc
gen
calbera Oct 2, 2024
0486a82
tests
calbera Oct 2, 2024
62d6d23
bet
calbera Oct 2, 2024
a795152
Wipg
calbera Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mod/consensus-types/pkg/types/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
package types

import (
"encoding/binary"

engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/primitives/pkg/bytes"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/constraints"
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
Expand Down Expand Up @@ -183,6 +187,24 @@ func (d *Deposit) GetTree() (*fastssz.Node, error) {
return fastssz.ProofTree(d)
}

/* -------------------------------------------------------------------------- */
/* EthLog */
/* -------------------------------------------------------------------------- */

// UnmarshalLog unmarshals the Deposit object from an Ethereum log.
//

func (d *Deposit) UnmarshalLog(log engineprimitives.Log) error {
idx := binary.BigEndian.Uint64(log.Data[152:160])
d.Index = idx
d.Pubkey = bytes.B48(log.Data[208:256])
amount := binary.BigEndian.Uint64(log.Data[280:288])
d.Amount = math.U64(amount)
d.Credentials = WithdrawalCredentials(bytes.B32(log.Data[288:320]))
d.Signature = bytes.B96(log.Data[352:448])
return nil
}

/* -------------------------------------------------------------------------- */
/* Getters and Setters */
/* -------------------------------------------------------------------------- */
Expand Down
4 changes: 2 additions & 2 deletions mod/da/pkg/da/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ type BlobSidecar interface {
IsNil() bool
}

// EventPublisher represents the event publisher interface.
// EventPublisherSubscriber represents the event publisher interface.
type EventPublisherSubscriber[T any] interface {
// PublishEvent publishes an event.
// Publish publishes an event.
calbera marked this conversation as resolved.
Show resolved Hide resolved
Publish(context.Context, T) error
// Subscribe subscribes to the event system.
Subscribe() (chan T, error)
Expand Down
138 changes: 138 additions & 0 deletions mod/engine-primitives/pkg/engine-primitives/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package engineprimitives

import (
"encoding/json"

"github.com/berachain/beacon-kit/mod/errors"
"github.com/berachain/beacon-kit/mod/primitives/pkg/bytes"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// Log represents a contract log event. These events are generated by the LOG
// opcode and
// stored/indexed by the node.
type Log struct {
// Consensus fields:
// address of the contract that generated the event
Address common.ExecutionAddress `json:"address"`
// list of topics provided by the contract.
Topics []common.ExecutionHash `json:"topics"`
// supplied by the contract, usually ABI-encoded
Data []byte `json:"data"`

// Derived fields. These fields are filled in by the node
// but not secured by consensus.
// block in which the transaction was included
BlockNumber uint64 `json:"blockNumber"`
// hash of the transaction
TxHash common.ExecutionHash `json:"transactionHash"`
// index of the transaction in the block
TxIndex uint `json:"transactionIndex"`
// hash of the block in which the transaction was included
BlockHash common.ExecutionHash `json:"blockHash"`
// index of the log in the block
Index uint `json:"logIndex"`
calbera marked this conversation as resolved.
Show resolved Hide resolved

// The Removed field is true if this log was reverted due to a chain
// reorganisation. You must pay attention to this field if you receive logs
// through a filter query.
Removed bool `json:"removed"`
calbera marked this conversation as resolved.
Show resolved Hide resolved
}

// MarshalJSON marshals as JSON.
func (l Log) MarshalJSON() ([]byte, error) {
type Log struct {
Address common.ExecutionAddress `json:"address"`
Topics []common.ExecutionHash `json:"topics"`
Data bytes.Bytes `json:"data"`
BlockNumber math.U64 `json:"blockNumber"`
TxHash common.ExecutionHash `json:"transactionHash"`
TxIndex math.U64 `json:"transactionIndex"`
BlockHash common.ExecutionHash `json:"blockHash"`
Index math.U64 `json:"logIndex"`
Removed bool `json:"removed"`
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
var enc Log
enc.Address = l.Address
enc.Topics = l.Topics
enc.Data = l.Data
enc.BlockNumber = math.U64(l.BlockNumber)
enc.TxHash = l.TxHash
enc.TxIndex = math.U64(l.TxIndex)
enc.BlockHash = l.BlockHash
enc.Index = math.U64(l.Index)
enc.Removed = l.Removed
return json.Marshal(&enc)
}

// UnmarshalJSON unmarshals from JSON.
func (l *Log) UnmarshalJSON(input []byte) error {
type Log struct {
Address *common.ExecutionAddress `json:"address"`
Topics []common.ExecutionHash `json:"topics"`
Data *bytes.Bytes `json:"data"`
BlockNumber *math.U64 `json:"blockNumber"`
TxHash *common.ExecutionHash `json:"transactionHash"`
TxIndex *math.U64 `json:"transactionIndex"`
BlockHash *common.ExecutionHash `json:"blockHash"`
Index *math.U64 `json:"logIndex"`
Removed *bool `json:"removed"`
}
var dec Log
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Address == nil {
return errors.New("missing required field 'address' for Log")
}
l.Address = *dec.Address
if dec.Topics == nil {
return errors.New("missing required field 'topics' for Log")
}
l.Topics = dec.Topics
if dec.Data == nil {
return errors.New("missing required field 'data' for Log")
}
l.Data = *dec.Data
if dec.BlockNumber != nil {
l.BlockNumber = uint64(*dec.BlockNumber)
}
if dec.TxHash == nil {
return errors.New("missing required field 'transactionHash' for Log")
}
l.TxHash = *dec.TxHash
if dec.TxIndex != nil {
l.TxIndex = uint(*dec.TxIndex)
}
if dec.BlockHash != nil {
l.BlockHash = *dec.BlockHash
}
if dec.Index != nil {
l.Index = uint(*dec.Index)
}
if dec.Removed != nil {
l.Removed = *dec.Removed
}
return nil
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 2 additions & 6 deletions mod/execution/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ require (
github.com/berachain/beacon-kit/mod/async v0.0.0-20240624204855-d8809d5c8588
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240618214413-d5ec0e66b3dd
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e
github.com/berachain/beacon-kit/mod/log v0.0.0-20240610210054-bfdc14c4013c
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240808194557-e72e74f58197
github.com/ethereum/go-ethereum v1.14.7
github.com/goccy/go-json v0.10.3
)

Expand All @@ -19,6 +17,7 @@ require (
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240703145037-b5612ab256db // indirect
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e // indirect
calbera marked this conversation as resolved.
Show resolved Hide resolved
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -30,23 +29,21 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.13.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/ethereum/c-kzg-4844 v1.0.3 // indirect
github.com/ethereum/go-ethereum v1.14.7 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
Expand All @@ -58,7 +55,6 @@ require (
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
Expand Down
Loading
Loading