mirror of
https://github.com/lux-apps/papers.git
synced 2026-10-30 18:15:21 +00:00
Restructured from flat .tex/.pdf files into per-paper subdirectories. Added Antje Worring as co-author on all papers. Synced PDFs to pdfs/ for download site.
49 lines
1.1 KiB
TeX
49 lines
1.1 KiB
TeX
\section{Implementation Details}
|
|
|
|
\label{sec:implementation}
|
|
|
|
The reference implementation in Go demonstrates key optimizations:
|
|
|
|
\subsection{Caching Layer}
|
|
|
|
\begin{lstlisting}[language=Go, caption=Opinion caching for performance]
|
|
type OpinionCache struct {
|
|
cache map[CacheKey]Opinion
|
|
ttl time.Duration
|
|
maxSize int
|
|
mutex sync.RWMutex
|
|
}
|
|
|
|
func (oc *OpinionCache) Get(node NodeID, txID TxID) (Opinion, bool) {
|
|
oc.mutex.RLock()
|
|
defer oc.mutex.RUnlock()
|
|
|
|
key := CacheKey{node, txID}
|
|
if op, exists := oc.cache[key]; exists {
|
|
if time.Since(op.Timestamp) < oc.ttl {
|
|
return op, true
|
|
}
|
|
}
|
|
return Opinion{}, false
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\subsection{Batch Processing}
|
|
|
|
\begin{lstlisting}[language=Go, caption=Batch consensus for multiple transactions]
|
|
func batchConsensus(txIDs []TxID) []Opinion {
|
|
results := make([]Opinion, len(txIDs))
|
|
samples := randomSample(k)
|
|
|
|
// Single network round for all transactions
|
|
responses := batchQuery(samples, txIDs)
|
|
|
|
for i, txID := range txIDs {
|
|
results[i] = processResponses(responses[txID])
|
|
}
|
|
|
|
return results
|
|
}
|
|
\end{lstlisting}
|
|
|