mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-26 05:27:19 +00:00
8a877c227a
* 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>
43 lines
1.8 KiB
Go
43 lines
1.8 KiB
Go
package silkworm
|
|
|
|
/*
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
typedef int (*SilkwormExecuteBlocksFunctionPointer)(void* txn, uint64_t chain_id, uint64_t start_block,
|
|
uint64_t max_block, uint64_t batch_size, bool write_receipts,
|
|
uint64_t* last_executed_block, int* lmdb_error_code);
|
|
|
|
int call_silkworm_execute_blocks(void* func_ptr, void* txn, uint64_t chain_id, uint64_t start_block, uint64_t max_block,
|
|
uint64_t batch_size, bool write_receipts, uint64_t* last_executed_block,
|
|
int* lmdb_error_code) {
|
|
return ((SilkwormExecuteBlocksFunctionPointer)func_ptr)(txn, chain_id, start_block, max_block, batch_size,
|
|
write_receipts, last_executed_block, lmdb_error_code);
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
"math/big"
|
|
"unsafe"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
)
|
|
|
|
func ExecuteBlocks(funcPtr unsafe.Pointer, txn ethdb.Tx, chainID *big.Int, startBlock uint64, maxBlock uint64, batchSize int, writeReceipts bool) (executedBlock uint64, err error) {
|
|
cChainId := C.uint64_t(chainID.Uint64())
|
|
cStartBlock := C.uint64_t(startBlock)
|
|
cMaxBlock := C.uint64_t(maxBlock)
|
|
cBatchSize := C.uint64_t(batchSize)
|
|
cWriteReceipts := C._Bool(writeReceipts)
|
|
cLastExecutedBlock := C.uint64_t(startBlock - 1)
|
|
cLmdbErrorCode := C.int(0)
|
|
status := C.call_silkworm_execute_blocks(funcPtr, txn.CHandle(), cChainId, cStartBlock, cMaxBlock, cBatchSize, cWriteReceipts, &cLastExecutedBlock, &cLmdbErrorCode)
|
|
executedBlock = uint64(cLastExecutedBlock)
|
|
if status == 0 || status == 1 {
|
|
return executedBlock, nil
|
|
}
|
|
return executedBlock, fmt.Errorf("silkworm_execute_blocks error %d, LMDB error %d", status, cLmdbErrorCode)
|
|
}
|