# vivpm/delegated-reputation-based-proof-of-probability-using-game-theory architecture

> Architecture diagram of the GitHub repository vivpm/delegated-reputation-based-proof-of-probability-using-game-theory, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory
- Repository: https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory

## Overview

##### Project type and purpose
- Project type: Full-node blockchain client (a customized Go-Ethereum implementation in Go).
- Purpose: Run an Ethereum-compatible node with a bespoke DRPoP-GT consensus engine (a game-theory-based staking algorithm replacing the standard ethash/PoS).

##### Top-level architectural layers
Layer your system into four horizontal slices:
A. Interfaces & Tools
– CLI binaries (cmd/geth, cmd/bootnode, cmd/puppeth, etc.)
– Console / interactive shell
– JSON-RPC & IPC server (rpc/, rpc/http.go, rpc/ipc.go)
– GraphQL server (graphql/)
B. Node Core
– node/ (lifecycle, config, rpcstack)
– internal/ (ethapi, jsre, web3ext)
– accounts & keystore management (accounts/, mobile/)
C. Networking & P2P
– libp2p-style transport & rlpx (p2p/rlpx/)
– Peer discovery (p2p/discover v4/v5, dnsdisc)
– Protocol handlers: ETH, LES, snap (eth/protocols/, les/, light/)
D. Blockchain Engine
– Consensus engine interface (consensus/)
- Default adapters: ethash, clique
- Your DRPoP-GT implementation (drop-in replacement under consensus/)
– Core chain logic (core/)
- Block validation, insertion, fork handling
- State transition / EVM (core/vm/)
- State DB & snapshotter (core/state/, trie/)
- Transaction pool (core/tx_pool.go)
– Local storage (rawdb, ethdb/)
– Transaction & event bus (event/)
– Miner (miner/)

##### Main components and how they interact
1. CLI “geth” process
– Parses flags, invokes node.New()
– Creates Node Core
– Hooks up P2P, Consensus, RPC, and Miner
2. Node Core
– node.Config sets up submodules
– node.APIStack exposes internal APIs to RPC & console
3. P2P subsystem
– Transport & encryption (rlpx)
– Discovery → peer table → peerset
– Protocol mux: routes ETH/LES traffic to eth.Handler, les.Handler
4. ETH Protocol Handler
– Receives blocks/txs, forwards to block processor
– Broadcasts local blocks/txs to peers
5. Consensus Engine
– Interface: consensus.Engine
– Your DRPoP-GT logic plugs here:
- Node list filtering → delegated nodes → two-stage game → miner selection
- Called by block inserter to authorize/validate next block
6. Core chain & EVM
– Validates blocks (block_validator.go), executes transactions in EVM
– Updates state DB (trie, rawdb)
7. Transaction Pool
– Holds pending txs, feeds miner
8. Miner
– Requests new block template from consensus engine
– Signs & seals block, hands off to ETH handler for broadcast
9. RPC/API Layer
– JSON-RPC & WebSocket: methods (eth, net, web3, personal) backed by internal ethapi
– GraphQL: read-only queries backed by service.go
10. Storage
– LevelDB via ethdb/leveldb for chain data
– Badger or in-memory options under ethdb/

##### Architectural patterns
- Modular layering: clearly separated CLI, Node Core, P2P, Consensus, Chain, API
- Plugin-style consensus interface: swap consensus.Engine implementations
- Event bus: decoupled modules communicate via event.Feed
- Layered storage abstraction: rawdb ⇄ core logic

##### Detailed checklist
[ ] Layer containers (Interfaces, Node Core, P2P, Blockchain Engine)
- CLI → Node Core
- Node Core ↔ Consensus Engine
- Node Core ↔ P2P → ETH/LES Handlers
- Handlers → Block Processor → Consensus Engine
- Consensus Engine → Core Chain → Storage
- Miner ← Tx Pool ← Core Chain
- RPC/API → Node Core → ethapi
[ ] Annotate key DRPoP-GT steps inside Consensus block:
- Node filtering, two-stage game, punishment, miner selection

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Interfaces & Tools
    subgraph "Interfaces & Tools"
        GetH["geth"]:::frontend
        Bootnode["bootnode"]:::frontend
        Puppeth["puppeth"]:::frontend
        Console["Console / Interactive Shell"]:::frontend
        HTTP["HTTP Server"]:::frontend
        IPC["IPC Server"]:::frontend
        RPCServer["RPC Server"]:::frontend
        GraphQLAPI["GraphQL API"]:::frontend
        GraphQLSvc["GraphQL Service"]:::frontend
        GraphQLSchema["GraphQL Schema"]:::frontend
    end

    %% Node Core Layer
    subgraph "Node Core"
        NodeLifecycle["Lifecycle"]:::core
        NodeConfig["Config"]:::core
        NodeRPCStack["RPC Stack"]:::core
    end

    subgraph "Internal APIs"
        EthAPI["ethapi"]:::core
        JSRE["jsre"]:::core
        Web3Ext["web3ext"]:::core
    end

    subgraph "Accounts & Keystore"
        Keystore["Keystore"]:::core
        Accounts["Accounts"]:::core
        MobileAccounts["Mobile Accounts"]:::core
    end

    %% Networking & P2P
    subgraph "Networking & P2P"
        Transport["Transport & Encryption (rlpx)"]:::network
        Discovery["Peer Discovery"]:::network
        DNSDisc["DNS Discovery"]:::network
        ETHHandler["ETH Handler"]:::network
        LESHandler["LES Handler"]:::network
        SnapHandler["Snap Handler"]:::network
    end

    %% Blockchain Engine
    subgraph "Blockchain Engine"
        ConsensusIface["Consensus Engine Interface"]:::consensus
        Ethash["Ethash Adapter"]:::consensus
        Clique["Clique Adapter"]:::consensus
        DRPoP["Consensus Engine (DRPoP-GT)"]:::consensus
        Validator["Block Validator"]:::core
        CoreChain["Core Chain & EVM"]:::core
        EVM["EVM"]:::core
        StateDB["State DB"]:::storage
        Snapshotter["Snapshotter"]:::storage
        TxPool["Transaction Pool"]:::core
        Miner["Miner"]:::core
        EventBus["Event Bus"]:::core
        LevelDB["LevelDB"]:::storage
        MemDB["MemoryDB"]:::storage
    end

    %% Connections
    GetH -->|starts| NodeLifecycle
    Bootnode -->|starts| NodeLifecycle
    Puppeth -->|starts| NodeLifecycle
    Console -->|shell| NodeRPCStack

    HTTP -->|rpc calls| EthAPI
    IPC -->|ipc calls| EthAPI
    RPCServer -->|serves| EthAPI

    GraphQLAPI -->|queries| GraphQLSvc
    GraphQLSvc -->|invokes| NodeRPCStack

    NodeLifecycle -->|configures| NodeConfig
    NodeConfig --> NodeRPCStack
    NodeRPCStack --> EthAPI
    NodeRPCStack --> JSRE
    NodeRPCStack --> Web3Ext

    NodeConfig --> Keystore
    NodeConfig --> Accounts
    NodeConfig --> MobileAccounts

    NodeLifecycle --> Transport
    Transport --> Discovery
    Discovery --> DNSDisc
    Transport --> ETHHandler
    Transport --> LESHandler
    Transport --> SnapHandler

    ETHHandler -->|forwards blocks| Validator
    LESHandler -->|forwards blocks| Validator
    SnapHandler -->|forwards| Validator

    Validator -->|auth/validate| ConsensusIface
    ConsensusIface --> Ethash
    ConsensusIface --> Clique
    ConsensusIface --> DRPoP
    DRPoP -->|game-theory staking| Validator

    Validator -->|execute txs| EVM
    EVM --> StateDB
    StateDB --> Snapshotter
    EVM --> LevelDB
    EVM --> MemDB

    EVM -->|new tx| TxPool
    TxPool -->|feeds| Miner
    Miner -->|seals block| ETHHandler

    EventBus -->|publishes| ETHHandler
    EventBus -->|publishes| LESHandler
    EventBus -->|publishes| SnapHandler
    EventBus -->|publishes| DRPoP

    %% Click Events
    click GetH "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/cmd/geth/main.go"
    click Bootnode "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/cmd/bootnode/main.go"
    click Puppeth "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/cmd/puppeth/puppeth.go"
    click Console "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/console/console.go"
    click HTTP "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/rpc/http.go"
    click IPC "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/rpc/ipc.go"
    click RPCServer "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/rpc/server.go"
    click GraphQLAPI "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/graphql/graphql.go"
    click GraphQLSvc "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/graphql/service.go"
    click GraphQLSchema "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/graphql/schema.go"
    click NodeLifecycle "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/node/lifecycle.go"
    click NodeConfig "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/node/config.go"
    click NodeRPCStack "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/node/rpcstack.go"
    click EthAPI "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/internal/ethapi/api.go"
    click JSRE "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/internal/jsre/jsre.go"
    click Web3Ext "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/internal/web3ext/web3ext.go"
    click Keystore "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/accounts/keystore/keystore.go"
    click Accounts "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/accounts/accounts.go"
    click MobileAccounts "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/mobile/accounts.go"
    click Transport "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/p2p/rlpx/rlpx.go"
    click Discovery "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/tree/main/p2p/discover"
    click DNSDisc "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/tree/main/p2p/dnsdisc"
    click ETHHandler "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/eth/protocols/eth/handler.go"
    click SnapHandler "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/eth/protocols/snap/handler.go"
    click LESHandler "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/les/server.go"
    click ConsensusIface "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/consensus/consensus.go"
    click Ethash "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/consensus/ethash/consensus.go"
    click Clique "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/consensus/clique/clique.go"
    click Validator "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/core/block_validator.go"
    click CoreChain "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/core/blockchain.go"
    click EVM "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/core/vm/evm.go"
    click StateDB "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/core/state/statedb.go"
    click Snapshotter "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/tree/main/core/state/snapshot"
    click TxPool "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/core/tx_pool.go"
    click EventBus "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/event/event.go"
    click Miner "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/miner/miner.go"
    click LevelDB "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/ethdb/leveldb/leveldb.go"
    click MemDB "https://github.com/vivpm/delegated-reputation-based-proof-of-probability-using-game-theory/blob/main/ethdb/memorydb/memorydb.go"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#000
    classDef network fill:#A9DFBF,stroke:#000
    classDef consensus fill:#F5B041,stroke:#000
    classDef core fill:#D5DBDB,stroke:#000
    classDef storage fill:#E5E7E9,stroke:#000
```
