From ecad0273ac08bad2af85686e6c1d13ea6b85c702 Mon Sep 17 00:00:00 2001 From: Tei Im Date: Thu, 4 Apr 2024 20:58:10 -0600 Subject: [PATCH] Revert "release 2.55: Revert PR 8829 (#8896)" This reverts commit b39f3245d48055627e06e2c508362e77ab766409. and this recovers https://github.com/ledgerwatch/erigon/pull/8829 Co-Authored-By: battlmonstr <11477595+battlmonstr@users.noreply.github.com> --- .github/workflows/ci.yml | 6 +- .github/workflows/test-integration-caplin.yml | 3 +- .github/workflows/test-integration.yml | 2 +- Dockerfile | 2 +- cmd/utils/flags.go | 11 +- eth/backend.go | 12 +- eth/ethconfig/config.go | 10 +- eth/stagedsync/stage_execute.go | 2 +- params/version.go | 33 +-- turbo/cli/default_flags.go | 1 - turbo/silkworm/load_unix.go | 37 ---- turbo/silkworm/load_windows.go | 16 -- turbo/silkworm/silkworm.go | 1 + turbo/silkworm/silkworm_api.h | 208 ------------------ turbo/silkworm/silkworm_api_bridge.h | 75 ------- turbo/silkworm/silkworm_go_devenv.sh | 49 +++++ 16 files changed, 74 insertions(+), 394 deletions(-) delete mode 100644 turbo/silkworm/load_unix.go delete mode 100644 turbo/silkworm/load_windows.go delete mode 100644 turbo/silkworm/silkworm_api.h delete mode 100644 turbo/silkworm/silkworm_api_bridge.h create mode 100755 turbo/silkworm/silkworm_go_devenv.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 262fe1e321c..c55727b70d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} strategy: matrix: - os: [ ubuntu-20.04, macos-11 ] # list of os: https://github.com/actions/virtual-environments + os: [ ubuntu-22.04, macos-13-xlarge ] # list of os: https://github.com/actions/virtual-environments runs-on: ${{ matrix.os }} steps: @@ -113,7 +113,7 @@ jobs: docker-build-check: # don't run this on devel - the PR must have run it to be merged and it misleads that this pushes the docker image if: (${{ github.event_name == 'push' || !github.event.pull_request.draft }}) && ${{ github.ref != 'refs/heads/devel' }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: AutoModality/action-clean@v1 - uses: actions/checkout@v3 @@ -129,7 +129,7 @@ jobs: # automated-tests: # runs-on: -# ubuntu-20.04 +# ubuntu-22.04 # if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} # steps: # - uses: actions/checkout@v3 diff --git a/.github/workflows/test-integration-caplin.yml b/.github/workflows/test-integration-caplin.yml index 40364197714..ca687f6df70 100644 --- a/.github/workflows/test-integration-caplin.yml +++ b/.github/workflows/test-integration-caplin.yml @@ -21,8 +21,7 @@ jobs: strategy: matrix: # disable macos-11 until https://github.com/ledgerwatch/erigon/issues/8789 -# os: [ ubuntu-20.04, macos-11 ] # list of os: https://github.com/actions/virtual-environments - os: [ ubuntu-20.04 ] # list of os: https://github.com/actions/virtual-environments + os: [ ubuntu-22.04 ] # list of os: https://github.com/actions/virtual-environments runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index 38c7564e981..a5871b4b1c0 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -14,7 +14,7 @@ jobs: tests: strategy: matrix: - os: [ ubuntu-20.04, macos-11 ] # list of os: https://github.com/actions/virtual-environments + os: [ ubuntu-22.04, macos-13-xlarge ] # list of os: https://github.com/actions/virtual-environments runs-on: ${{ matrix.os }} steps: diff --git a/Dockerfile b/Dockerfile index 1f8d4558b48..5dcc693147e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ ADD . . RUN --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/tmp/go-build \ --mount=type=cache,target=/go/pkg/mod \ - make all + make BUILD_TAGS=nosqlite,noboltdb,nosilkworm all FROM docker.io/library/golang:1.20-alpine3.17 AS tools-builder diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0f80b8bbc7b..a3874d253a7 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -909,11 +909,6 @@ var ( Usage: "Comma separated list of support session ids to connect to", } - SilkwormLibraryPathFlag = cli.StringFlag{ - Name: "silkworm.libpath", - Usage: "Path to the Silkworm library", - Value: "", - } SilkwormExecutionFlag = cli.BoolFlag{ Name: "silkworm.exec", Usage: "Enable Silkworm block execution", @@ -926,6 +921,7 @@ var ( Name: "silkworm.sentry", Usage: "Enable embedded Silkworm Sentry service", } + BeaconAPIFlag = cli.BoolFlag{ Name: "beacon.api", Usage: "Enable beacon API", @@ -1640,10 +1636,7 @@ func setCaplin(ctx *cli.Context, cfg *ethconfig.Config) { } func setSilkworm(ctx *cli.Context, cfg *ethconfig.Config) { - cfg.SilkwormLibraryPath = ctx.String(SilkwormLibraryPathFlag.Name) - if ctx.IsSet(SilkwormExecutionFlag.Name) { - cfg.SilkwormExecution = ctx.Bool(SilkwormExecutionFlag.Name) - } + cfg.SilkwormExecution = ctx.Bool(SilkwormExecutionFlag.Name) cfg.SilkwormRpcDaemon = ctx.Bool(SilkwormRpcDaemonFlag.Name) cfg.SilkwormSentry = ctx.Bool(SilkwormSentryFlag.Name) } diff --git a/eth/backend.go b/eth/backend.go index d6371d97caf..98739f4ee2e 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -361,8 +361,8 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger backend.gasPrice, _ = uint256.FromBig(config.Miner.GasPrice) - if config.SilkwormLibraryPath != "" { - backend.silkworm, err = silkworm.New(config.SilkwormLibraryPath, config.Dirs.DataDir) + if config.SilkwormExecution || config.SilkwormRpcDaemon || config.SilkwormSentry { + backend.silkworm, err = silkworm.New(config.Dirs.DataDir) if err != nil { return nil, err } @@ -403,7 +403,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger MaxPeers: p2pConfig.MaxPeers, } - silkwormSentryService := backend.silkworm.NewSentryService(settings) + silkwormSentryService := silkworm.NewSentryService(backend.silkworm, settings) backend.silkwormSentryService = &silkwormSentryService sentryClient, err := sentry_multi_client.GrpcClient(backend.sentryCtx, apiAddr) @@ -980,7 +980,7 @@ func (s *Ethereum) Init(stack *node.Node, config *ethconfig.Config) error { s.apiList = jsonrpc.APIList(chainKv, ethRpcClient, txPoolRpcClient, miningRpcClient, ff, stateCache, blockReader, s.agg, &httpRpcCfg, s.engine, s.seqRPCService, s.historicalRPCService, s.logger) if config.SilkwormRpcDaemon && httpRpcCfg.Enabled { - silkwormRPCDaemonService := s.silkworm.NewRpcDaemonService(chainKv) + silkwormRPCDaemonService := silkworm.NewRpcDaemonService(s.silkworm, chainKv) s.silkwormRPCDaemonService = &silkwormRPCDaemonService } else { go func() { @@ -1462,7 +1462,9 @@ func (s *Ethereum) Stop() error { } } if s.silkworm != nil { - s.silkworm.Close() + if err := s.silkworm.Close(); err != nil { + s.logger.Error("silkworm.Close error", "err", err) + } } return nil diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 2f68f6f2922..b21d037bd0a 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -106,9 +106,6 @@ var Defaults = Config{ KeepBlocks: false, Produce: true, }, - - // applies if SilkwormLibraryPath is set - SilkwormExecution: true, } func init() { @@ -269,10 +266,9 @@ type Config struct { ForcePartialCommit bool // Embedded Silkworm support - SilkwormLibraryPath string - SilkwormExecution bool - SilkwormRpcDaemon bool - SilkwormSentry bool + SilkwormExecution bool + SilkwormRpcDaemon bool + SilkwormSentry bool DisableTxPoolGossip bool diff --git a/eth/stagedsync/stage_execute.go b/eth/stagedsync/stage_execute.go index 909ef540c3b..8a512eba3e2 100644 --- a/eth/stagedsync/stage_execute.go +++ b/eth/stagedsync/stage_execute.go @@ -465,7 +465,7 @@ Loop: _, isMemoryMutation := tx.(*membatchwithdb.MemoryMutation) if cfg.silkworm != nil && !isMemoryMutation { - blockNum, err = cfg.silkworm.ExecuteBlocks(tx, cfg.chainConfig.ChainID, blockNum, to, uint64(cfg.batchSize), writeChangeSets, writeReceipts, writeCallTraces) + blockNum, err = silkworm.ExecuteBlocks(cfg.silkworm, tx, cfg.chainConfig.ChainID, blockNum, to, uint64(cfg.batchSize), writeChangeSets, writeReceipts, writeCallTraces) } else { err = executeBlock(block, tx, batch, cfg, *cfg.vmConfig, writeChangeSets, writeReceipts, writeCallTraces, initialCycle, stateStream, logger) } diff --git a/params/version.go b/params/version.go index f2ddc962a4f..f0124a73738 100644 --- a/params/version.go +++ b/params/version.go @@ -29,47 +29,24 @@ var ( GitTag string ) -// Version is the version of upstream erigon // see https://calver.org const ( - VersionMajor = 2 // Major version component of the current release - VersionMinor = 56 // Minor version component of the current release - VersionMicro = 2 // Patch version component of the current release - VersionModifier = "" // Modifier component of the current release + VersionMajor = 2 // Major version component of the current release + VersionMinor = 38 // Minor version component of the current release + VersionMicro = 0 // Patch version component of the current release + VersionModifier = "stable" // Modifier component of the current release VersionKeyCreated = "ErigonVersionCreated" VersionKeyFinished = "ErigonVersionFinished" ) -// OPVersion is the version of op-erigon -const ( - OPVersionMajor = 0 // Major version component of the current release - OPVersionMinor = 5 // Minor version component of the current release - OPVersionMicro = 0 // Patch version component of the current release - OPVersionModifier = "unstable" // Version metadata to append to the version string -) - // Version holds the textual version string. var Version = func() string { - return fmt.Sprintf("%d.%02d.%d", OPVersionMajor, OPVersionMinor, OPVersionMicro) + return fmt.Sprintf("%d.%02d.%d", VersionMajor, VersionMinor, VersionMicro) }() // VersionWithMeta holds the textual version string including the metadata. var VersionWithMeta = func() string { v := Version - if OPVersionModifier != "" { - v += "-" + OPVersionModifier - } - return v -}() - -// ErigonVersion holds the textual erigon version string. -var ErigonVersion = func() string { - return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionMicro) -}() - -// ErigonVersionWithMeta holds the textual erigon version string including the metadata. -var ErigonVersionWithMeta = func() string { - v := ErigonVersion if VersionModifier != "" { v += "-" + VersionModifier } diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index f9b86911e7d..597a893dace 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -175,7 +175,6 @@ var DefaultFlags = []cli.Flag{ &utils.GenesisPathFlag, &utils.OtsSearchMaxCapFlag, - &utils.SilkwormLibraryPathFlag, &utils.SilkwormExecutionFlag, &utils.SilkwormRpcDaemonFlag, &utils.SilkwormSentryFlag, diff --git a/turbo/silkworm/load_unix.go b/turbo/silkworm/load_unix.go deleted file mode 100644 index 11a22c74822..00000000000 --- a/turbo/silkworm/load_unix.go +++ /dev/null @@ -1,37 +0,0 @@ -//go:build unix - -package silkworm - -/* -#cgo LDFLAGS: -ldl -#include -#include -*/ -import "C" - -import ( - "fmt" - "unsafe" -) - -func OpenLibrary(dllPath string) (unsafe.Pointer, error) { - cPath := C.CString(dllPath) - defer C.free(unsafe.Pointer(cPath)) - dllHandle := C.dlopen(cPath, C.RTLD_LAZY) - if dllHandle == nil { - err := C.GoString(C.dlerror()) - return nil, fmt.Errorf("failed to load dynamic library %s: %s", dllPath, err) - } - return dllHandle, nil -} - -func LoadFunction(dllHandle unsafe.Pointer, funcName string) (unsafe.Pointer, error) { - cName := C.CString(funcName) - defer C.free(unsafe.Pointer(cName)) - funcPtr := C.dlsym(dllHandle, cName) - if funcPtr == nil { - err := C.GoString(C.dlerror()) - return nil, fmt.Errorf("failed to find the %s function: %s", funcName, err) - } - return funcPtr, nil -} diff --git a/turbo/silkworm/load_windows.go b/turbo/silkworm/load_windows.go deleted file mode 100644 index 537411083c1..00000000000 --- a/turbo/silkworm/load_windows.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build windows - -package silkworm - -import ( - "errors" - "unsafe" -) - -func OpenLibrary(dllPath string) (unsafe.Pointer, error) { - return nil, errors.New("not implemented") -} - -func LoadFunction(dllHandle unsafe.Pointer, funcName string) (unsafe.Pointer, error) { - return nil, errors.New("not implemented") -} diff --git a/turbo/silkworm/silkworm.go b/turbo/silkworm/silkworm.go index 8f8ea427317..72d5c1b7293 100644 --- a/turbo/silkworm/silkworm.go +++ b/turbo/silkworm/silkworm.go @@ -7,6 +7,7 @@ import ( "github.com/erigontech/silkworm-go" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon/consensus" + "math/big" ) type Silkworm = silkworm_go.Silkworm diff --git a/turbo/silkworm/silkworm_api.h b/turbo/silkworm/silkworm_api.h deleted file mode 100644 index 9d3e655837a..00000000000 --- a/turbo/silkworm/silkworm_api.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - Copyright 2023 The Silkworm Authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#ifndef SILKWORM_API_H_ -#define SILKWORM_API_H_ - -// C API exported by Silkworm to be used in Erigon. - -#include // NOLINT(*-deprecated-headers) -#include // NOLINT(*-deprecated-headers) -#include // NOLINT(*-deprecated-headers) - -#if defined _MSC_VER -#define SILKWORM_EXPORT __declspec(dllexport) -#else -#define SILKWORM_EXPORT __attribute__((visibility("default"))) -#endif - -#if __cplusplus -#define SILKWORM_NOEXCEPT noexcept -#else -#define SILKWORM_NOEXCEPT -#endif - -#if __cplusplus -extern "C" { -#endif - -// Silkworm library error codes (SILKWORM_OK indicates no error, i.e. success) - -#define SILKWORM_OK 0 -#define SILKWORM_INTERNAL_ERROR 1 -#define SILKWORM_UNKNOWN_ERROR 2 -#define SILKWORM_INVALID_HANDLE 3 -#define SILKWORM_INVALID_PATH 4 -#define SILKWORM_INVALID_SNAPSHOT 5 -#define SILKWORM_INVALID_MDBX_TXN 6 -#define SILKWORM_INVALID_BLOCK_RANGE 7 -#define SILKWORM_BLOCK_NOT_FOUND 8 -#define SILKWORM_UNKNOWN_CHAIN_ID 9 -#define SILKWORM_MDBX_ERROR 10 -#define SILKWORM_INVALID_BLOCK 11 -#define SILKWORM_DECODING_ERROR 12 -#define SILKWORM_TOO_MANY_INSTANCES 13 -#define SILKWORM_INVALID_SETTINGS 14 -#define SILKWORM_TERMINATION_SIGNAL 15 -#define SILKWORM_SERVICE_ALREADY_STARTED 16 - -typedef struct MDBX_env MDBX_env; -typedef struct MDBX_txn MDBX_txn; - -struct SilkwormInstance; -typedef struct SilkwormInstance* SilkwormHandle; - -struct SilkwormMemoryMappedFile { - const char* file_path; - uint8_t* memory_address; - uint64_t memory_length; -}; - -struct SilkwormHeadersSnapshot { - struct SilkwormMemoryMappedFile segment; - struct SilkwormMemoryMappedFile header_hash_index; -}; - -struct SilkwormBodiesSnapshot { - struct SilkwormMemoryMappedFile segment; - struct SilkwormMemoryMappedFile block_num_index; -}; - -struct SilkwormTransactionsSnapshot { - struct SilkwormMemoryMappedFile segment; - struct SilkwormMemoryMappedFile tx_hash_index; - struct SilkwormMemoryMappedFile tx_hash_2_block_index; -}; - -struct SilkwormChainSnapshot { - struct SilkwormHeadersSnapshot headers; - struct SilkwormBodiesSnapshot bodies; - struct SilkwormTransactionsSnapshot transactions; -}; - -#define SILKWORM_PATH_SIZE 260 - -struct SilkwormSettings { - //! Data directory path in UTF-8. - char data_dir_path[SILKWORM_PATH_SIZE]; -}; - -/** - * \brief Initialize the Silkworm C API library. - * \param[in,out] handle Silkworm instance handle returned on successful initialization. - * \param[in] settings General Silkworm settings. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure. - */ -SILKWORM_EXPORT int silkworm_init( - SilkwormHandle* handle, - const struct SilkwormSettings* settings) SILKWORM_NOEXCEPT; - -/** - * \brief Build a set of indexes for the given snapshots. - * \param[in] handle A valid Silkworm instance handle, got with silkworm_init. - * \param[in] snapshots An array of snapshots to index. - * \param[in] indexPaths An array of paths to write indexes to. - * Note that the name of the index is a part of the path and it is used to determine the index type. - * \param[in] len The number of snapshots and paths. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure on some or all indexes. - */ -SILKWORM_EXPORT int silkworm_build_recsplit_indexes(SilkwormHandle handle, struct SilkwormMemoryMappedFile* snapshots[], int len) SILKWORM_NOEXCEPT; - -/** - * \brief Notify Silkworm about a new snapshot to use. - * \param[in] handle A valid Silkworm instance handle, got with silkworm_init. - * \param[in] snapshot A snapshot to use. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure. - */ -SILKWORM_EXPORT int silkworm_add_snapshot(SilkwormHandle handle, struct SilkwormChainSnapshot* snapshot) SILKWORM_NOEXCEPT; - -/** - * \brief Start Silkworm RPC daemon. - * \param[in] handle A valid Silkworm instance handle, got with silkworm_init.Must not be zero. - * \param[in] env An valid MDBX environment. Must not be zero. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure. - */ -SILKWORM_EXPORT int silkworm_start_rpcdaemon(SilkwormHandle handle, MDBX_env* env) SILKWORM_NOEXCEPT; - -/** - * \brief Stop Silkworm RPC daemon and wait for its termination. - * \param[in] handle A valid Silkworm instance handle, got with silkworm_init. Must not be zero. - * \param[in] snapshot A snapshot to use. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure. - */ -SILKWORM_EXPORT int silkworm_stop_rpcdaemon(SilkwormHandle handle) SILKWORM_NOEXCEPT; - -#define SILKWORM_SENTRY_SETTINGS_CLIENT_ID_SIZE 128 -#define SILKWORM_SENTRY_SETTINGS_NAT_SIZE 50 -#define SILKWORM_SENTRY_SETTINGS_NODE_KEY_SIZE 32 -#define SILKWORM_SENTRY_SETTINGS_PEERS_MAX 128 -#define SILKWORM_SENTRY_SETTINGS_PEER_URL_SIZE 200 - -struct SilkwormSentrySettings { - char client_id[SILKWORM_SENTRY_SETTINGS_CLIENT_ID_SIZE]; - uint16_t api_port; - uint16_t port; - char nat[SILKWORM_SENTRY_SETTINGS_NAT_SIZE]; - uint64_t network_id; - uint8_t node_key[SILKWORM_SENTRY_SETTINGS_NODE_KEY_SIZE]; - char static_peers[SILKWORM_SENTRY_SETTINGS_PEERS_MAX][SILKWORM_SENTRY_SETTINGS_PEER_URL_SIZE]; - char bootnodes[SILKWORM_SENTRY_SETTINGS_PEERS_MAX][SILKWORM_SENTRY_SETTINGS_PEER_URL_SIZE]; - bool no_discover; - size_t max_peers; -}; - -SILKWORM_EXPORT int silkworm_sentry_start(SilkwormHandle handle, const struct SilkwormSentrySettings* settings) SILKWORM_NOEXCEPT; -SILKWORM_EXPORT int silkworm_sentry_stop(SilkwormHandle handle) SILKWORM_NOEXCEPT; - -/** - * \brief Execute a batch of blocks and write resulting changes into the database. - * \param[in] handle A valid Silkworm instance handle, got with silkworm_init. - * \param[in] txn A valid read-write MDBX transaction. Must not be zero. - * This function does not commit nor abort the transaction. - * \param[in] chain_id EIP-155 chain ID. SILKWORM_UNKNOWN_CHAIN_ID is returned in case of an unknown or unsupported chain. - * \param[in] start_block The block height to start the execution from. - * \param[in] max_block Do not execute after this block. - * max_block may be executed, or the execution may stop earlier if the batch is full. - * \param[in] batch_size The size of DB changes to accumulate before returning from this method. - * Pass 0 if you want to execute just 1 block. - * \param[in] write_change_sets Whether to write state changes into the DB. - * \param[in] write_receipts Whether to write CBOR-encoded receipts into the DB. - * \param[in] write_call_traces Whether to write call traces into the DB. - * \param[out] last_executed_block The height of the last successfully executed block. - * Not written to if no blocks were executed, otherwise *last_executed_block ≤ max_block. - * \param[out] mdbx_error_code If an MDBX error occurs (this function returns kSilkwormMdbxError) - * and mdbx_error_code isn't NULL, it's populated with the relevant MDBX error code. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure. - * SILKWORM_BLOCK_NOT_FOUND is probably OK: it simply means that the execution reached the end of the chain - * (blocks up to and incl. last_executed_block were still executed). - */ -SILKWORM_EXPORT int silkworm_execute_blocks( - SilkwormHandle handle, MDBX_txn* txn, uint64_t chain_id, uint64_t start_block, uint64_t max_block, - uint64_t batch_size, bool write_change_sets, bool write_receipts, bool write_call_traces, - uint64_t* last_executed_block, int* mdbx_error_code) SILKWORM_NOEXCEPT; - -/** - * \brief Finalize the Silkworm C API library. - * \param[in] handle A valid Silkworm instance handle got with silkworm_init. - * \return SILKWORM_OK (=0) on success, a non-zero error value on failure. - */ -SILKWORM_EXPORT int silkworm_fini(SilkwormHandle handle) SILKWORM_NOEXCEPT; - -#if __cplusplus -} -#endif - -#endif // SILKWORM_API_H_ diff --git a/turbo/silkworm/silkworm_api_bridge.h b/turbo/silkworm/silkworm_api_bridge.h deleted file mode 100644 index 4cf482f1887..00000000000 --- a/turbo/silkworm/silkworm_api_bridge.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright 2023 The Silkworm Authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#ifndef SILKWORM_API_FUNC_H_ -#define SILKWORM_API_FUNC_H_ - -#include "silkworm_api.h" - -typedef int (*silkworm_init_func)(SilkwormHandle* handle, const struct SilkwormSettings* settings); - -int call_silkworm_init_func(void* func_ptr, SilkwormHandle* handle, const struct SilkwormSettings* settings) { - return ((silkworm_init_func)func_ptr)(handle, settings); -} - -typedef int (*silkworm_add_snapshot_func)(SilkwormHandle handle, struct SilkwormChainSnapshot* snapshot); - -int call_silkworm_add_snapshot_func(void* func_ptr, SilkwormHandle handle, struct SilkwormChainSnapshot* snapshot) { - return ((silkworm_add_snapshot_func)func_ptr)(handle, snapshot); -} - -typedef int (*silkworm_start_rpcdaemon_func)(SilkwormHandle handle, MDBX_env* env); - -int call_silkworm_start_rpcdaemon_func(void* func_ptr, SilkwormHandle handle, MDBX_env* env) { - return ((silkworm_start_rpcdaemon_func)func_ptr)(handle, env); -} - -typedef int (*silkworm_stop_rpcdaemon_func)(SilkwormHandle handle); - -int call_silkworm_stop_rpcdaemon_func(void* func_ptr, SilkwormHandle handle) { - return ((silkworm_stop_rpcdaemon_func)func_ptr)(handle); -} - -typedef int (*silkworm_sentry_start_func)(SilkwormHandle handle, const struct SilkwormSentrySettings* settings); - -int call_silkworm_sentry_start_func(void* func_ptr, SilkwormHandle handle, const struct SilkwormSentrySettings* settings) { - return ((silkworm_sentry_start_func)func_ptr)(handle, settings); -} - -typedef int (*silkworm_sentry_stop_func)(SilkwormHandle handle); - -int call_silkworm_sentry_stop_func(void* func_ptr, SilkwormHandle handle) { - return ((silkworm_sentry_stop_func)func_ptr)(handle); -} - -typedef int (*silkworm_execute_blocks_func)(SilkwormHandle handle, MDBX_txn* txn, uint64_t chain_id, uint64_t start_block, - uint64_t max_block, uint64_t batch_size, bool write_change_sets, bool write_receipts, bool write_call_traces, - uint64_t* last_executed_block, int* mdbx_error_code); - -int call_silkworm_execute_blocks_func(void* func_ptr, SilkwormHandle handle, MDBX_txn* txn, uint64_t chain_id, uint64_t start_block, - uint64_t max_block, uint64_t batch_size, bool write_change_sets, bool write_receipts, bool write_call_traces, - uint64_t* last_executed_block, int* mdbx_error_code) { - return ((silkworm_execute_blocks_func)func_ptr)(handle, txn, chain_id, start_block, max_block, batch_size, write_change_sets, - write_receipts, write_call_traces, last_executed_block, mdbx_error_code); -} - -typedef int (*silkworm_fini_func)(SilkwormHandle handle); - -int call_silkworm_fini_func(void* func_ptr, SilkwormHandle handle) { - return ((silkworm_fini_func)func_ptr)(handle); -} - -#endif // SILKWORM_API_FUNC_H_ diff --git a/turbo/silkworm/silkworm_go_devenv.sh b/turbo/silkworm/silkworm_go_devenv.sh new file mode 100755 index 00000000000..79ebb808a6a --- /dev/null +++ b/turbo/silkworm/silkworm_go_devenv.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e +set -o pipefail + +TARGET="silkworm_capi" +script_dir=$(dirname "${BASH_SOURCE[0]}") +project_dir=$(realpath "$script_dir/../..") + +src_dir="$1" +build_dir="$2" + +if [[ ! -d "$src_dir" ]] +then + echo "source directory '$src_dir' not found" + exit 1 +fi + +if [[ -z "$build_dir" ]] +then + build_dir="$src_dir/build" +fi + +if [[ ! -d "$build_dir" ]] +then + echo "build directory '$build_dir' not found" + exit 1 +fi + +replace_dir=$(mktemp -d -t silkworm-go 2> /dev/null || mktemp -d -t silkworm-go.XXXXXXXX) + +git clone --depth 1 "https://github.com/erigontech/silkworm-go" "$replace_dir" + +ln -s "$src_dir/silkworm/capi/silkworm.h" "$replace_dir/include/" + +product_dir="$build_dir/silkworm/capi" +product_path=$(echo "$product_dir/"*$TARGET*) +product_file_name=$(basename "$product_path") + +for platform in macos_arm64 macos_x64 linux_arm64 linux_x64 +do + mkdir "$replace_dir/lib/$platform" + ln -s "$product_path" "$replace_dir/lib/$platform/$product_file_name" +done + +cd "$project_dir/.." +rm -f "go.work" +go work init "$project_dir" +go work use "$replace_dir"