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

Unit test for config module #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3e7a9af
Implemented unit testing for networks.go
VeerChaurasia Sep 20, 2024
751af81
Implement Test for types.go
VeerChaurasia Sep 21, 2024
fd4da66
Implemented test for utils.go
VeerChaurasia Sep 21, 2024
f5d2a70
Refined networks_test.go
VeerChaurasia Sep 21, 2024
f538b63
Resolved linter workflow error
VeerChaurasia Sep 21, 2024
c4f68b8
Changed Deserliaze Slot to recieve number as an string
VeerChaurasia Sep 21, 2024
93ea6f4
Implmeneted tests for checkpoint.go
VeerChaurasia Sep 21, 2024
118da07
Updated utils.go to resolve linter error
VeerChaurasia Sep 21, 2024
a383721
Resolved error
VeerChaurasia Sep 22, 2024
c901ba7
Resolved database error
VeerChaurasia Sep 21, 2024
1755999
Created consensus.go_util.go and edited consensuscore,rpc and types …
DarkLord017 Sep 21, 2024
f02b0a7
Edited logging mistake in consensus.go
DarkLord017 Sep 21, 2024
8b15cf3
Fixed linter errors in consensus
DarkLord017 Sep 21, 2024
eeb46ab
Used merkle tree library for utils
DarkLord017 Sep 21, 2024
b6819dd
Revert "Used merkle tree library for utils"
DarkLord017 Sep 21, 2024
7443b3b
Used merkle tree library for utils
DarkLord017 Sep 21, 2024
c6627da
Update utils.go
DarkLord017 Sep 21, 2024
261f6d3
Update utils.go using merkle tree library
DarkLord017 Sep 21, 2024
c978ef2
Update consensus.go to resolve comments
DarkLord017 Sep 21, 2024
36baa55
Update README.md
star-gazer111 Sep 21, 2024
6821401
Update README.md
DarkLord017 Sep 21, 2024
6bf1194
Move utils.go functions from common to utils directory
DarkLord017 Sep 21, 2024
e662b4f
Deleted utils.go
DarkLord017 Sep 21, 2024
88ff896
Code in config directory uses utils package
DarkLord017 Sep 21, 2024
cfcb8c9
Code in config directory uses utils package
DarkLord017 Sep 21, 2024
d1cec02
Remove utils from config
DarkLord017 Sep 21, 2024
7433b81
Remove utils from consensus and move to utils
DarkLord017 Sep 21, 2024
e4e4fe0
Moved utils of consensus too
DarkLord017 Sep 22, 2024
c37979d
Corrected tests to use consesnsus_Core for forks
DarkLord017 Sep 22, 2024
e01e30d
Corrected tests to use consesnsus_Core for forks
DarkLord017 Sep 22, 2024
940938d
Resolved the imports
VeerChaurasia Sep 22, 2024
ba17479
Removed config.toml
VeerChaurasia Sep 22, 2024
5a82aae
Resolved linter workflow error
VeerChaurasia Sep 22, 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
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
![build](https://github.com/BlocSoc-iitr/selene/actions/workflows/go.yml/badge.svg)
![tests](https://github.com/BlocSoc-iitr/selene/actions/workflows/test.yml/badge.svg)
![linter](https://github.com/BlocSoc-iitr/selene/actions/workflows/cilint.yml/badge.svg)

Expand All @@ -7,6 +6,41 @@
Selene is a fast, open source, portable & secure light client for Ethereum written in Golang. We plan to ship Selene as the underlying software behind wallets that use light clients. We derived our inspiration from [Helios](https://github.com/a16z/helios) which is a light client written in Rust. The project is in active maintenance on the [dev](https://github.com/BlocSoc-iitr/selene/tree/dev) branch.

# Architecture
![Selene Architecture](https://github.com/user-attachments/assets/db7eb9d7-5bc3-4911-a849-1b2d05239942)
## Data Flow

1. The Consensus Layer provides sync information and verified block headers to the RPC Server.
2. The RPC Server passes block information and verified headers to the Execution Layer.
3. The Execution Layer validates Merkle proofs based on the state root and requested data.

## Centralised RPC Server
This server acts as an intermediary between the Consensus and Execution layers. It handles:

* Providing block headers of previous blocks from checkpoint to the latest block<br>
* Transmitting block gossip of block head<br>
* Passing verified block headers to the Execution Layer<br>

## Execution Layer
The Execution Layer is responsible for processing transactions and maintaining the current state of the blockchain. It includes:

A `Validate Merkle Proofs` field that:

Takes state root and requested data as input
Outputs a boolean (true/false) indicating the validity of the Merkle proof

## Consensus Layer

The Consensus Layer is responsible for maintaining agreement on the state of the blockchain across the network. It includes:

* Getting weak subjectivity checkpoints
* Logic for determining **current and next sync committees**
* A **Syncing** process that:
* Uses sync committee makeup to fetch previous block headers
* Syncs for each sync committee period (~27 hours) up to the latest block
* A **verify bls sig** function that:
* Takes `blsaggsig` and `blspubkey[]` as input
* This function verifies a BLS aggregate signature. It accepts the aggregated signature (blsaggsig) and an array of public keys (blspubkey[]), returning a boolean value that indicates whether the signature is
valid.

# Installing
Yet to come.
Expand Down
65 changes: 50 additions & 15 deletions common/types.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package common

//other option is to import a package of go-ethereum but that was weird
import (
"encoding/json"
"fmt"
"math/big"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"
"strconv"
)

// need to confirm how such primitive types will be imported,
//
// Transaction https://docs.rs/alloy/latest/alloy/rpc/types/struct.Transaction.html
// address: 20 bytes
// B256: 32 bytes https://bluealloy.github.io/revm/docs/revm/precompile/primitives/type.B256.html
type Address struct {
Addr [20]byte
}
Expand All @@ -40,37 +37,72 @@ type Block struct {
Transactions Transactions
TransactionsRoot [32]byte
Uncles [][32]byte
BlobGasUsed *uint64
ExcessBlobGas *uint64
}

// an enum having 2 types- how to implement??
type Transactions struct {
Hashes [][32]byte
Full []types.Transaction //transaction needs to be defined
Full []Transaction // transaction needs to be defined
}

type Transaction struct {
AccessList types.AccessList
Hash common.Hash
Nonce uint64
BlockHash [32]byte
BlockNumber *uint64
TransactionIndex uint64
From string
To *common.Address
Value *big.Int
GasPrice *big.Int
Gas uint64
Input []byte
ChainID *big.Int
TransactionType uint8
Signature *Signature
MaxFeePerGas *big.Int
MaxPriorityFeePerGas *big.Int
MaxFeePerBlobGas *big.Int
BlobVersionedHashes []common.Hash
}

type Signature struct {
R string
S string
V uint64
YParity Parity
}

type Parity struct {
Value bool
}

func Default() *Transactions {
return &Transactions{
Full: []types.Transaction{},
Full: []Transaction{},
}
}

func (t *Transactions) HashesFunc() [][32]byte {
if len(t.Hashes) > 0 { //if Transactions struct contains hashes then return them directly
if len(t.Hashes) > 0 {
return t.Hashes
}
hashes := make([][32]byte, len(t.Full))
for i := range t.Full {
hashes[i] = t.Full[i].Hash()
hashes[i] = t.Full[i].Hash // Use the Hash field directly
}
return hashes
}

func (t Transactions) MarshalJSON() ([]byte, error) {
if len(t.Hashes) > 0 {
return json.Marshal(t.Hashes)
}
return json.Marshal(t.Full)
}

// can be an enum
type BlockTag struct {
Latest bool
Finalized bool
Expand Down Expand Up @@ -106,18 +138,21 @@ func (b *BlockTag) UnmarshalJSON(data []byte) error {
}
return nil
}

func parseBlockNumber(block string) (uint64, error) {
if len(block) > 2 && block[:2] == "0x" {
return parseHexUint64(block[2:])
}
return parseDecimalUint64(block)
}

func parseHexUint64(hexStr string) (uint64, error) {
return strconv.ParseUint(hexStr, 16, 64)
}

func parseDecimalUint64(decStr string) (uint64, error) {
return strconv.ParseUint(decStr, 10, 64)
}

// need some error structs and enums as well
// Example BlockNotFoundError
// Example error structs can be defined here
// type BlockNotFoundError struct {}
49 changes: 0 additions & 49 deletions common/utils.go

This file was deleted.

26 changes: 14 additions & 12 deletions config/base.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package config

import "github.com/BlocSoc-iitr/selene/consensus/consensus_core"

// base config for a network

type BaseConfig struct {
RpcBindIp string `json:"rpc_bind_ip"`
RpcPort uint16 `json:"rpc_port"`
ConsensusRpc *string `json:"consensus_rpc"`
DefaultCheckpoint [32]byte `json:"default_checkpoint"` // In cli.go, checkpoint is currently taken as []byte{}
Chain ChainConfig `json:"chain"` // but it should be [32]byte as it is a hash
Forks Forks `json:"forks"`
MaxCheckpointAge uint64 `json:"max_checkpoint_age"`
DataDir *string `json:"data_dir"`
LoadExternalFallback bool `json:"load_external_fallback"`
StrictCheckpointAge bool `json:"strict_checkpoint_age"`
RpcBindIp string `json:"rpc_bind_ip"`
RpcPort uint16 `json:"rpc_port"`
ConsensusRpc *string `json:"consensus_rpc"`
DefaultCheckpoint [32]byte `json:"default_checkpoint"` // In cli.go, checkpoint is currently taken as []byte{}
Chain ChainConfig `json:"chain"` // but it should be [32]byte as it is a hash
Forks consensus_core.Forks `json:"forks"`
MaxCheckpointAge uint64 `json:"max_checkpoint_age"`
DataDir *string `json:"data_dir"`
LoadExternalFallback bool `json:"load_external_fallback"`
StrictCheckpointAge bool `json:"strict_checkpoint_age"`
}

// implement a default method for the above struct
Expand All @@ -24,10 +26,10 @@ func (b BaseConfig) Default() BaseConfig {
ConsensusRpc: nil,
DefaultCheckpoint: [32]byte{},
Chain: ChainConfig{},
Forks: Forks{},
Forks: consensus_core.Forks{},
MaxCheckpointAge: 0,
DataDir: nil,
LoadExternalFallback: false,
StrictCheckpointAge: false,
}
}
}
Loading
Loading