erigon-pulse/cmd/tg/main.go
Andrew Ashikhmin 8a877c227a
Integrate Silkworm execution (#1344)
* Expose C Handle of lmdbTx

* LoadExecutionFunctionPointer

* silkworm ExecuteBlocks

* linter

* CLI flag for SilkwormExecutionFunc

* linter

* Call SilkwormExecutionFunc in SpawnExecuteBlocksStage

* Commit transaction after Silkworm execution

* Fix batch initialization

* Make batch_size uint64_t instead of size_t

* max_block in silkworm_execute_blocks

* More accurate logProgress

* Use CHandle exposed by lmdb-go

* Enable Silkworm on Linux only

* Update lmdb-go

* Error when attempting to use Silkworm not on Linux

* Move SilkwormFlag from cmd/utils/flags.go to turbo/cli/flags.go

* Integrate Silkworm into cmd/integration

* Check against ReaderBuilder/WriterBuilder/ChangeSetHook in Silkworm execution

* Refactor SpawnExecuteBlocksStage

* linters

* Small clean-ups

* Move ChangeSetHook inside executeBlockWithGo

* No need to tamper with batch size in executeBlocksWithSilkworm

* fix

* Fix

* Fixup

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2020-11-28 15:08:02 +00:00

65 lines
1.7 KiB
Go

package main
import (
"fmt"
"net"
"os"
"unsafe"
"github.com/ledgerwatch/turbo-geth/cmd/utils"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync"
"github.com/ledgerwatch/turbo-geth/log"
turbocli "github.com/ledgerwatch/turbo-geth/turbo/cli"
"github.com/ledgerwatch/turbo-geth/turbo/node"
"github.com/ledgerwatch/turbo-geth/turbo/silkworm"
"github.com/urfave/cli"
)
var (
// gitCommit is injected through the build flags (see Makefile)
gitCommit string
)
func main() {
// creating a turbo-api app with all defaults
app := turbocli.MakeApp(runTurboGeth, turbocli.DefaultFlags)
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func runTurboGeth(cliCtx *cli.Context) {
silkwormPath := cliCtx.String(turbocli.SilkwormFlag.Name)
var silkwormExecutionFunc unsafe.Pointer
if silkwormPath != "" {
var err error
silkwormExecutionFunc, err = silkworm.LoadExecutionFunctionPointer(silkwormPath)
if err != nil {
panic(fmt.Errorf("failed to load Silkworm dynamic library: %v", err))
}
}
// creating staged sync with all default parameters
sync := stagedsync.New(
stagedsync.DefaultStages(),
stagedsync.DefaultUnwindOrder(),
stagedsync.OptionalParameters{SilkwormExecutionFunc: silkwormExecutionFunc},
)
ctx := utils.RootContext()
// initializing the node and providing the current git commit there
tg := node.New(cliCtx, sync, node.Params{GitCommit: gitCommit})
tg.SetP2PListenFunc(func(network, addr string) (net.Listener, error) {
var lc net.ListenConfig
return lc.Listen(ctx, network, addr)
})
// running the node
err := tg.Serve()
if err != nil {
log.Error("error while serving a turbo-geth node", "err", err)
}
}