From d498c26c3fb4597d41472fded46616b428375991 Mon Sep 17 00:00:00 2001 From: Dmitrii Skopintsev Date: Wed, 25 Jun 2025 18:56:08 +0200 Subject: [PATCH] Panic on concurrent block updates --- nil/internal/consensus/ibft/logger.go | 4 ++-- nil/internal/execution/postprocess.go | 12 +++++++++++- nil/services/nilservice/service.go | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nil/internal/consensus/ibft/logger.go b/nil/internal/consensus/ibft/logger.go index 5331bb91b..e45b06afe 100644 --- a/nil/internal/consensus/ibft/logger.go +++ b/nil/internal/consensus/ibft/logger.go @@ -7,11 +7,11 @@ type ibftLogger struct { } func (l *ibftLogger) Info(msg string, args ...any) { - l.logger.Info().Fields(args).Msg(msg) + l.logger.Trace().Fields(args).Msg(msg) } func (l *ibftLogger) Debug(msg string, args ...any) { - l.logger.Debug().Fields(args).Msg(msg) + l.logger.Trace().Fields(args).Msg(msg) } func (l *ibftLogger) Error(msg string, args ...any) { diff --git a/nil/internal/execution/postprocess.go b/nil/internal/execution/postprocess.go index 9a7ba1bb1..997d01887 100644 --- a/nil/internal/execution/postprocess.go +++ b/nil/internal/execution/postprocess.go @@ -1,11 +1,13 @@ package execution import ( + "bytes" "errors" "fmt" "github.com/NilFoundation/nil/nil/common" "github.com/NilFoundation/nil/nil/common/assert" + "github.com/NilFoundation/nil/nil/common/check" "github.com/NilFoundation/nil/nil/internal/db" "github.com/NilFoundation/nil/nil/internal/types" ) @@ -43,8 +45,16 @@ func (pp *blockPostprocessor) fillLastBlockTable() error { } func (pp *blockPostprocessor) fillBlockHashByNumberIndex() error { + key := pp.blockResult.Block.Id.Bytes() + value := pp.blockResult.BlockHash.Bytes() + + present, err := pp.tx.GetFromShard(pp.shardId, db.BlockHashByNumberIndex, key) + check.PanicIfNot(err == nil || errors.Is(err, db.ErrKeyNotFound)) + check.PanicIfNotf(err != nil || bytes.Equal(value, present), "block hash by number index already exists: %x != %x", + present, value) + return pp.tx.PutToShard( - pp.shardId, db.BlockHashByNumberIndex, pp.blockResult.Block.Id.Bytes(), pp.blockResult.BlockHash.Bytes()) + pp.shardId, db.BlockHashByNumberIndex, key, value) } func (pp *blockPostprocessor) fillBlockHashAndTransactionIndexByTransactionHash() error { diff --git a/nil/services/nilservice/service.go b/nil/services/nilservice/service.go index 530728183..c5a19af62 100644 --- a/nil/services/nilservice/service.go +++ b/nil/services/nilservice/service.go @@ -60,7 +60,7 @@ func startRpcServer( httpConfig := &httpcfg.HttpCfg{ HttpURL: addr, HttpCompression: true, - TraceRequests: true, + TraceRequests: false, HTTPTimeouts: httpcfg.DefaultHTTPTimeouts, HttpCORSDomain: []string{"*"}, KeepHeaders: []string{"Client-Version", "Client-Type", "X-UID"},