mirror of
https://github.com/lux-apps/papers.git
synced 2026-10-30 18:15:21 +00:00
98 lines
3.0 KiB
TeX
98 lines
3.0 KiB
TeX
\section{G-Chain Architecture}
|
|
|
|
|
|
\subsection{System Overview}
|
|
|
|
\begin{figure}[h]
|
|
\centering
|
|
\begin{verbatim}
|
|
+--------------------------------------------------------------+
|
|
| G-Chain Architecture |
|
|
+-----------------------+--------------------------------------+
|
|
| Storage Layer | Query Layer |
|
|
+-----------------------+--------------------------------------+
|
|
| * BadgerDB backend | * GraphVM interpreter |
|
|
| * Verkle trie commits | * GraphQL compiler |
|
|
| * Cross-chain refs | * Gas metering |
|
|
| * Selective sync | * Result serialization |
|
|
+-----------------------+--------------------------------------+
|
|
v v
|
|
+-----------------+ +-------------------+
|
|
| EVM Integration| | External Access |
|
|
+-----------------+ +-------------------+
|
|
| * Precompiles | | * GraphQL HTTP |
|
|
| (0x0B-0x11) | | * WebSocket |
|
|
| * On-chain | | * ZAP wire |
|
|
| queries | | * Client SDKs |
|
|
+-----------------+ +-------------------+
|
|
\end{verbatim}
|
|
\caption{G-Chain architectural layers}
|
|
\end{figure}
|
|
|
|
\subsection{Core Components}
|
|
|
|
\subsubsection{GraphDB Backend (lux/graphdb)}
|
|
|
|
BadgerDB-based storage with blockchain-specific optimizations:
|
|
|
|
\begin{lstlisting}[language=Go, basicstyle=\small\ttfamily]
|
|
type GraphDB struct {
|
|
db *badger.DB
|
|
verkle *verkle.Trie
|
|
chainMap map[ChainID]*ChainIndex
|
|
|
|
// Horizontal scaling
|
|
syncMode SyncMode // Full/Chain/App-specific
|
|
chainFilter []ChainID // Selective sync
|
|
|
|
// Custom indexing
|
|
customIndexes map[string]*Index
|
|
}
|
|
|
|
// Key-value model
|
|
// Nodes: Node:<chain>:<type>:<id>
|
|
// Edges: Edge:<chain>:<src_type>:<src_id>:<relation>:<dst>
|
|
// XRefs: XRef:<src_chain>:<dst_chain>:<id>
|
|
\end{lstlisting}
|
|
|
|
\subsubsection{GraphVM Interpreter (luxfi/graphql)}
|
|
|
|
Compiles GraphQL queries to bytecode with gas metering:
|
|
|
|
\begin{lstlisting}[language=Go, basicstyle=\small\ttfamily]
|
|
type GraphVM struct {
|
|
compiler *Compiler
|
|
executor *Executor
|
|
gasMeter *GasMeter
|
|
}
|
|
|
|
// Bytecode instruction set
|
|
type OpCode uint8
|
|
const (
|
|
OP_LOAD_NODE OpCode = 0x01 // 100 gas
|
|
OP_TRAVERSE OpCode = 0x02 // 50 gas per edge
|
|
OP_FILTER OpCode = 0x03 // 20 gas per comparison
|
|
OP_AGGREGATE OpCode = 0x04 // 500 gas
|
|
OP_JOIN OpCode = 0x05 // 200 gas per join
|
|
)
|
|
\end{lstlisting}
|
|
|
|
\subsubsection{EVM Precompiles}
|
|
|
|
\begin{table}[h]
|
|
\centering
|
|
\begin{tabular}{@{}llr@{}}
|
|
\toprule
|
|
\textbf{Address} & \textbf{Function} & \textbf{Gas Cost} \\ \midrule
|
|
0x0B & AddNode & 50,000 + size \\
|
|
0x0C & UpdateNode & 30,000 + size \\
|
|
0x0D & DeleteNode & 20,000 \\
|
|
0x0E & AddEdge & 40,000 \\
|
|
0x0F & UpdateEdge & 25,000 \\
|
|
0x10 & DeleteEdge & 15,000 \\
|
|
0x11 & VerifyProof & 80,000 + depth \\ \bottomrule
|
|
\end{tabular}
|
|
\caption{G-Chain EVM precompile gas costs}
|
|
\end{table}
|
|
|