Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
17b9396
WIP: start work on verifier
nibty Dec 6, 2023
9f0a5cb
WIP
nibty Dec 6, 2023
b500109
create new context on each hash for thread safey
nibty Dec 6, 2023
2efbe8a
add validator readme
nibty Dec 6, 2023
8a5653e
update the github action to install argon2
nibty Dec 6, 2023
af31ecd
update the github action to install argon2
nibty Dec 6, 2023
f69395e
update the github action to install libargon2-dev
nibty Dec 6, 2023
1c97384
add validator count cache, fix shouldvote
nibty Dec 7, 2023
5d3ddfb
add validator count cache, fix shouldvote
nibty Dec 7, 2023
c32bb83
no need to extra salt, we already have it
nibty Dec 7, 2023
9361c54
separate event listen from verifier
nibty Dec 7, 2023
54d27c0
split argon result once to get hash
nibty Dec 7, 2023
2e68e39
fix key decoding
nibty Dec 7, 2023
7a8e1c5
add test
nibty Dec 7, 2023
ade155f
add difficulty verification, superblock time check by block insertion
nibty Dec 7, 2023
6045b60
remove stop method from verifier
nibty Dec 7, 2023
a92c119
expand token parser
nibty Dec 8, 2023
0caaf04
gracefully exit event listener
nibty Dec 8, 2023
a63ad67
use the in-process API handle
nibty Dec 8, 2023
de7e9a5
add hashId to logs
nibty Dec 8, 2023
6f3bc1b
update token names
nibty Dec 13, 2023
5adc2d5
add voting
nibty Dec 15, 2023
ff974e5
move voter into event listener
nibty Dec 15, 2023
f2ceac5
update blockstore contract. refactor voter. add mutex
nibty Dec 18, 2023
735fd50
WIP
nibty Dec 19, 2023
6cc2a03
WIP
nibty Dec 19, 2023
967ce37
decode record bytes in go
nibty Dec 19, 2023
58a098d
Revert "decode record bytes in go"
nibty Dec 19, 2023
594e702
go back to using on-chain method for decoding and shouldvote. add syn…
nibty Dec 20, 2023
6dd7a77
fix unit tests
nibty Dec 20, 2023
c6b2763
better start and shutdown of event listener
nibty Dec 20, 2023
d3c4591
disable xuni timestamp checks until configed blocknumber
nibty Dec 20, 2023
55386e2
add support for new on chain token parsing
nibty Jan 5, 2024
922bf88
use getLogs on newHash logs per block rather than listening for event…
nibty Jan 9, 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
10 changes: 8 additions & 2 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: update apt
run: sudo apt update

- name: Install argon2
run: sudo apt install -y libargon2-dev

- name: Golang dependency
uses: actions/setup-go@v3
with:
Expand All @@ -21,10 +27,10 @@ jobs:
run: go test -v ./...

- name: Build
run: make opera
run: make x1

- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: "./build/opera"
artifacts: "./build/x1"
token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 10 additions & 4 deletions .github/workflows/test_build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Check build

on:
on:
push:
pull_request:
branches:
branches:
- develop
- master

Expand All @@ -14,6 +14,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: update apt
run: sudo apt update

- name: Install argon2
run: sudo apt install -y libargon2-dev

- name: Golang dependency
uses: actions/setup-go@v3
with:
Expand All @@ -23,10 +29,10 @@ jobs:
run: go test -v ./...

- name: Build
run: make opera
run: make x1

- name: Publish
uses: actions/upload-artifact@v2
with:
name: opera
path: ./build/opera
path: ./build/x1
107 changes: 107 additions & 0 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cmd/opera/launcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ func mayMakeAllConfigs(ctx *cli.Context) (*config, error) {
cfg.XenBlocks.Endpoint = endpoint
}

cfg.XenBlocks.ForceVerifier = ctx.GlobalIsSet(XenBlocksVerifierEnabledFlag.Name)
cfg.XenBlocks.VerifierAddress = common.HexToAddress(ctx.GlobalString(XenBlocksVerifierAddressFlag.Name))

// Load config file (medium priority)
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
if err := loadAllConfigs(file, &cfg); err != nil {
Expand Down
27 changes: 26 additions & 1 deletion cmd/opera/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package launcher
import (
"fmt"
"github.com/Fantom-foundation/go-opera/integration/xenblocks/reporter"
"github.com/Fantom-foundation/go-opera/integration/xenblocks/verifier"
"path"
"sort"
"strings"
Expand Down Expand Up @@ -185,6 +186,8 @@ func initFlags() {

xenblocksFlags = []cli.Flag{
XenBlocksEndpointFlag,
XenBlocksVerifierEnabledFlag,
XenBlocksVerifierAddressFlag,
}

nodeFlags = []cli.Flag{}
Expand Down Expand Up @@ -349,6 +352,26 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) (
}
signer := valkeystore.NewSigner(valKeystore)

// Config the XenBlocks verifier
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
passwords := utils.MakePasswordList(ctx)

var account accounts.Account
if cfg.Emitter.Validator.ID != 0 || cfg.XenBlocks.ForceVerifier {
account, _ = unlockAccount(ks, cfg.XenBlocks.VerifierAddress.Hex(), 0, passwords)
}
xbEventListener := verifier.NewEventListener(stack, cfg.Emitter.Validator.ID, ks, account, gdb.GetRules().NetworkID)
if cfg.Emitter.Validator.ID != 0 || cfg.XenBlocks.ForceVerifier {

// Set validator ID to 1 if it is not set
// this is only needed for testing
if cfg.Emitter.Validator.ID == 0 {
xbEventListener.SetValidatorId(1)
}

go xbEventListener.Start()
}

// Config the XenBlocks reporter
xenblocksReporter := reporter.NewReporter(cfg.XenBlocks)

Expand All @@ -365,13 +388,14 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) (
if stop {
go func() {
// do it in a separate thread to avoid deadlock
xbEventListener.Close()
_ = stack.Close()
}()
return true
}
return false
}
svc, err := gossip.NewService(stack, cfg.Opera, gdb, blockProc, engine, dagIndex, newTxPool, haltCheck, xenblocksReporter)
svc, err := gossip.NewService(stack, cfg.Opera, gdb, blockProc, engine, dagIndex, newTxPool, haltCheck, xenblocksReporter, xbEventListener)
if err != nil {
utils.Fatalf("Failed to create the service: %v", err)
}
Expand All @@ -389,6 +413,7 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) (
stack.RegisterLifecycle(svc)

return stack, svc, func() {
xbEventListener.Close()
_ = stack.Close()
gdb.Close()
_ = cdb.Close()
Expand Down
10 changes: 10 additions & 0 deletions cmd/opera/launcher/xenblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ var XenBlocksEndpointFlag = cli.StringFlag{
Usage: "Sets the Xenblocks reporter endpoint.",
}

var XenBlocksVerifierEnabledFlag = cli.BoolFlag{
Name: "xenblocks-force-verifier",
Usage: "Force enable the Xenblocks verifier even if not a validator.",
}

var XenBlocksVerifierAddressFlag = cli.StringFlag{
Name: "xenblocks-verifier-addr",
Usage: "The account to sign verifier tx with",
}

func parseXenBlocksEndpoint(s string) (url string, err error) {
if !strings.HasPrefix(s, "ws://") && !strings.HasPrefix(s, "wss://") {
err = fmt.Errorf("use ws:// or wss:// prefix")
Expand Down
13 changes: 13 additions & 0 deletions genabis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

cat ../xenblock-tokens/artifacts/contracts/VoteManager.sol/VoteManager.json | jq '.abi' > VoteManager.abi.json
go run github.com/ethereum/go-ethereum/cmd/abigen --abi VoteManager.abi.json --pkg votemanager > integration/xenblocks/contracts/votemanager/votemanager.go
rm VoteManager.abi.json

cat ../xenblock-tokens/artifacts/contracts/TokenRegistry.sol/TokenRegistry.json | jq '.abi' > TokenRegistry.abi.json
go run github.com/ethereum/go-ethereum/cmd/abigen --abi TokenRegistry.abi.json --pkg tokenregistry > integration/xenblocks/contracts/tokenregistry/tokenregistry.go
rm TokenRegistry.abi.json

cat ../x1-block-storage/build/contracts/BlockStorage.json | jq '.abi' > BlockStorage.abi.json
go run github.com/ethereum/go-ethereum/cmd/abigen --abi BlockStorage.abi.json --pkg block_storage > integration/xenblocks/contracts/block_storage/block_storage.go
rm BlockStorage.abi.json
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/Fantom-foundation/go-ethereum v1.10.8-ftm-rc12
require github.com/tvdburgt/go-argon2 v0.0.0-20181109175329-49d0f0e5973c

//replace github.com/ethereum/go-ethereum => github.com/Fantom-foundation/go-ethereum v1.10.8-ftm-rc12
replace github.com/ethereum/go-ethereum => github.com/nibty/go-ethereum v1.10.8-ftm-rc12-x1-3

replace github.com/dvyukov/go-fuzz => github.com/guzenok/go-fuzz v0.0.0-20210201043429-a8e90a2a4f88

Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mo
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Fantom-foundation/go-ethereum v1.10.8-ftm-rc12 h1:SyXrKgZNRBIQN1XZXOH1WZZoPft2qm0jC7pZC9nRCw4=
github.com/Fantom-foundation/go-ethereum v1.10.8-ftm-rc12/go.mod h1:IeQDjWCNBj/QiWIPosfF6/kRC6pHPNs7W7LfBzjj+P4=
github.com/Fantom-foundation/lachesis-base v0.0.0-20230817040848-1326ba9aa59b h1:/9+Cau3cWaKy9fQk/NWq3RJKrwEjgrhME6ACy4RjLns=
github.com/Fantom-foundation/lachesis-base v0.0.0-20230817040848-1326ba9aa59b/go.mod h1:Ogv5etzSmM2rQ4eN3OfmyitwWaaPjd4EIDiW/NAbYGk=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
Expand Down Expand Up @@ -490,6 +488,8 @@ github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo
github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM=
github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nibty/go-ethereum v1.10.8-ftm-rc12-x1-3 h1:v07QogU/zZE/wqi5ny0uos/IcjuhU+Mi2Q4VE/H5P+o=
github.com/nibty/go-ethereum v1.10.8-ftm-rc12-x1-3/go.mod h1:IeQDjWCNBj/QiWIPosfF6/kRC6pHPNs7W7LfBzjj+P4=
github.com/nibty/recws v0.0.0-20231129011923-06823df0d0db h1:5NSkB+3RDcKx0fWRPCsNiyORrCzYLzoCip6q83SKdn4=
github.com/nibty/recws v0.0.0-20231129011923-06823df0d0db/go.mod h1:i6EuUq15zzNHzljFI2bM6FdxOTRlvw6vthcDaOQjenU=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
Expand Down Expand Up @@ -622,6 +622,8 @@ github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITn
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tvdburgt/go-argon2 v0.0.0-20181109175329-49d0f0e5973c h1:ZUBYitup1fOHz1sXBG4gVpTrSDOCQ1TAJgg6ANJDWc8=
github.com/tvdburgt/go-argon2 v0.0.0-20181109175329-49d0f0e5973c/go.mod h1:vF0GTqOQNLQNidMrh6zrEDpGczXEgBpZ6iuZvtisD5s=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/tyler-smith/go-bip39 v1.0.2 h1:+t3w+KwLXO6154GNJY+qUtIxLTmFjfUmpguQT1OlOT8=
github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
Expand Down
12 changes: 9 additions & 3 deletions gossip/c_block_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gossip
import (
"fmt"
"github.com/Fantom-foundation/go-opera/integration/xenblocks/reporter"
"github.com/Fantom-foundation/go-opera/integration/xenblocks/verifier"
"sort"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -76,6 +77,7 @@ func (s *Service) GetConsensusCallbacks() lachesis.ConsensusCallbacks {
s.verWatcher,
&s.bootstrapping,
s.reporter,
s.eventListener,
),
}
}
Expand All @@ -93,7 +95,8 @@ func consensusCallbackBeginBlockFn(
emitters *[]*emitter.Emitter,
verWatcher *verwatcher.VerWarcher,
bootstrapping *bool,
xenblocks *reporter.Reporter,
xenblocksReporter *reporter.Reporter,
xenblocksEL *verifier.EventListener,
) lachesis.BeginBlockFn {
return func(cBlock *lachesis.Block) lachesis.BlockCallbacks {
if *bootstrapping {
Expand Down Expand Up @@ -246,6 +249,7 @@ func consensusCallbackBeginBlockFn(
txListener := blockProc.TxListenerModule.Start(blockCtx, bs, es, statedb)
onNewLogAll := func(l *types.Log) {
txListener.OnNewLog(l)

// Note: it's possible for logs to get indexed twice by BR and block processing
if verWatcher != nil {
verWatcher.OnNewLog(l)
Expand Down Expand Up @@ -449,12 +453,14 @@ func consensusCallbackBeginBlockFn(
"age", utils.PrettyDuration(blockAge), "t", utils.PrettyDuration(now.Sub(start)))
blockAgeGauge.Update(int64(blockAge.Nanoseconds()))

if xenblocks.Enabled {
xenblocks.Send(
if xenblocksReporter.Enabled {
xenblocksReporter.Send(
fmt.Sprintf("%d", blockCtx.Idx),
fmt.Sprintf("%s", block.Atropos),
fmt.Sprintf("%s", utils.PrettyDuration(now.Sub(start))))
}

xenblocksEL.OnNewBlock(uint64(blockCtx.Idx))
}
if confirmedEvents.Len() != 0 {
atomic.StoreUint32(blockBusyFlag, 1)
Expand Down
9 changes: 5 additions & 4 deletions gossip/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/Fantom-foundation/go-opera/integration/xenblocks/reporter"
"github.com/Fantom-foundation/go-opera/integration/xenblocks/verifier"
"math/big"
"math/rand"
"sync"
Expand Down Expand Up @@ -158,14 +159,14 @@ type Service struct {

bootstrapping bool

reporter *reporter.Reporter

reporter *reporter.Reporter
eventListener *verifier.EventListener
logger.Instance
}

func NewService(stack *node.Node, config Config, store *Store, blockProc BlockProc,
engine lachesis.Consensus, dagIndexer *vecmt.Index, newTxPool func(evmcore.StateReader) TxPool,
haltCheck func(oldEpoch, newEpoch idx.Epoch, age time.Time) bool, reporter *reporter.Reporter) (*Service, error) {
haltCheck func(oldEpoch, newEpoch idx.Epoch, age time.Time) bool, reporter *reporter.Reporter, listener *verifier.EventListener) (*Service, error) {
if err := config.Validate(); err != nil {
return nil, err
}
Expand All @@ -183,7 +184,7 @@ func NewService(stack *node.Node, config Config, store *Store, blockProc BlockPr
svc.netRPCService = ethapi.NewPublicNetAPI(svc.p2pServer, store.GetRules().NetworkID)
svc.haltCheck = haltCheck
svc.reporter = reporter.Start(svc.p2pServer)

svc.eventListener = listener
return svc, nil
}

Expand Down
Loading