Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9e7c6f1
feat: implement CatchUpSync functionality for improved block synchron…
saishibunb Jun 23, 2026
4de0d71
feat: enhance catchup command and synchronization logic
saishibunb Jun 23, 2026
58069c2
fix: update catchup synchronization logic and dependency cleanup
saishibunb Jun 23, 2026
57c57c1
Fix fastsy
saishibunb Jun 23, 2026
b83a402
chore(deps): update JMDN-FastSync dependency version in go.mod
saishibunb Jun 23, 2026
5e27aae
fix: improve immudb data writing and synchronization logic
saishibunb Jun 23, 2026
f6f26bb
fix: correct block data synchronization logic in catchup process
saishibunb Jun 23, 2026
f522abb
fix: update JMDN-FastSync dependency version and enhance catchup sync…
saishibunb Jun 23, 2026
03cbc7f
chore(deps): update JMDN-FastSync dependency version in go.mod and go…
saishibunb Jun 23, 2026
5094817
fix: enhance account writing and synchronization logic in immudb_acco…
saishibunb Jun 23, 2026
e095665
fix: enhance account reconciliation during catchup synchronization
saishibunb Jun 23, 2026
3b5ebb5
fix: add diagnostic counters for block synchronization in catchup pro…
saishibunb Jun 23, 2026
b3be6fe
fix: optimize transaction retrieval and account writing logic
saishibunb Jun 23, 2026
901add5
fix: enhance account reconciliation in catchup synchronization
saishibunb Jun 23, 2026
9eb826b
fix: improve batch account update handling in immudb_account_manager
saishibunb Jun 23, 2026
83e2307
fix: update JMDN-FastSync dependency version and enhance logging in c…
saishibunb Jun 23, 2026
61bffd8
fix: update JMDN-FastSync dependency version in go.mod and go.sum
saishibunb Jun 23, 2026
5b21261
fix: update JMDN-FastSync dependency version and add transaction retr…
saishibunb Jun 24, 2026
3b1d92e
fix: update JMDN-FastSync dependency version and increase max connect…
saishibunb Jun 24, 2026
49a4b77
fix: enhance account update structure and reconciliation logic
saishibunb Jun 24, 2026
c9f4eda
fix: add EnableCatchup configuration for automatic catchup synchroniz…
saishibunb Jun 24, 2026
9bfbbd7
refactor: simplify HandleCatchUpSync logic by removing default fromBl…
saishibunb Jun 24, 2026
e9f087e
enhance: improve logging and progress tracking in HandleCatchUpSync
saishibunb Jun 24, 2026
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ internal/WAL/.tmp/*
.code-review-graph/*
.cursor/*
test_results/
docs/FASTSYNC_V3_MIGRATION_PLAN.md
eventlog.duckdb
Scripts/sign_tx.go
storage/thebe-kv/000017.vlog
storage/thebe-kv/000018.vlog
storage/thebe-kv/DISCARD
storage/thebe-kv/KEYREGISTRY
storage/thebe-kv/MANIFEST
storage/thebe-kv/outbox.db
dlq/DLQ.log
jmdn2
43 changes: 41 additions & 2 deletions CLI/CLI.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -107,8 +108,9 @@ func PrintFuncs() {
fmt.Println(" mempoolStats - Show mempool statistics")
fmt.Println(" stats - Show messaging statistics")
fmt.Println(" broadcast <message> - Broadcast a message to all connected peers")
fmt.Println(" fastsync <peer_multiaddr> - Fast sync blockchain data with a peer (V2 Engine)")
fmt.Println(" accountsync <peer_multiaddr> - Sync missing accounts only (skip block sync)")
fmt.Println(" fastsync <peer_multiaddr> - Fast sync blockchain data with a peer (V2 Engine)")
fmt.Println(" catchup <peer_multiaddr> [from_block] - Catch up to chain tip; from_block defaults to auto-detect (localTip+1)")
fmt.Println(" accountsync <peer_multiaddr> - Sync missing accounts only (skip block sync)")
fmt.Println(" dbstate - Show current ImmuDB database state")
fmt.Println(" propagateDID <did> <public_key> - Propagate a DID to the network")
fmt.Println(" getDID <did> - Get a DID document from the network")
Expand Down Expand Up @@ -268,6 +270,8 @@ func (h *CommandHandler) handleCommand(parts []string) {
h.handleBroadcast(parts)
case "fastsync", "fastsyncv2", "firstsync":
h.handleFastSync(parts)
case "catchup":
h.handleCatchUpSync(parts)
case "accountsync":
h.handleAccountSync(parts)
case "propagateDID":
Expand Down Expand Up @@ -632,6 +636,41 @@ func (h *CommandHandler) handleFastSync(parts []string) {
printDashes()
}

func (h *CommandHandler) handleCatchUpSync(parts []string) {
if len(parts) < 2 {
fmt.Println("Usage: catchup <peer_multiaddr> [from_block]")
fmt.Println(" peer_multiaddr full multiaddr with peer ID, e.g. /ip4/1.2.3.4/tcp/15000/p2p/12D3KooW...")
fmt.Println(" from_block optional; defaults to 0 (auto-detect from local DB tip)")
fmt.Println(" pass 1 to force a full scan from genesis")
return
}
if h.FastSyncerV2 == nil {
fmt.Println("Error: FastsyncV2 engine is not initialized")
return
}

var fromBlock uint64
if len(parts) >= 3 {
var err error
fromBlock, err = strconv.ParseUint(parts[2], 10, 64)
if err != nil {
fmt.Printf("Invalid from_block %q: %v\n", parts[2], err)
return
}
} // fromBlock=0 → auto-detect inside HandleCatchUpSync

fmt.Printf("Starting catch-up sync (from_block=%d) with peer %s\n", fromBlock, parts[1])
startTime := time.Now()

if err := h.FastSyncerV2.HandleCatchUpSync(fromBlock, parts[1]); err != nil {
fmt.Printf("CatchUpSync failed: %v\n", err)
return
}

fmt.Printf("CatchUpSync completed in %v\n", time.Since(startTime))
printDashes()
}

func (h *CommandHandler) handleAccountSync(parts []string) {
if len(parts) != 2 {
fmt.Println("Usage: accountsync <peer_multiaddr>")
Expand Down
32 changes: 32 additions & 0 deletions CLI/CLI_GRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,38 @@ func (h *CommandHandler) HandleFastSyncV2(peeraddr string) (SyncStats, error) {
}, nil
}

func (h *CommandHandler) HandleCatchUpSync(peeraddr string, fromBlock uint64) (SyncStats, error) {
if peeraddr == "" {
return SyncStats{}, fmt.Errorf("usage: catchup <peer_multiaddr> [from_block]")
}
// fromBlock=0 → auto-detect inside HandleCatchUpSync
if !h.PullAllowed {
return SyncStats{}, fmt.Errorf("node is configured as a serve-only participant (pulling disabled). cannot pull data")
}
if h.FastSyncerV2 == nil {
return SyncStats{}, fmt.Errorf("FastsyncV2 engine is inactive")
}

startTime := time.Now().UTC()
if err := h.FastSyncerV2.HandleCatchUpSync(fromBlock, peeraddr); err != nil {
return SyncStats{}, fmt.Errorf("CatchUpSync failed: %w", err)
}

var newMainState, newAccountsState *schema.ImmutableState
if h.MainClient != nil {
newMainState, _ = DB_OPs.GetDatabaseState(h.MainClient.Client)
}
if h.DIDClient != nil {
newAccountsState, _ = DB_OPs.GetDatabaseState(h.DIDClient.Client)
}

return SyncStats{
TimeTaken: time.Since(startTime),
MainState: newMainState,
AccountsState: newAccountsState,
}, nil
}

func (h *CommandHandler) HandleAccountSync(peeraddr string) (SyncStats, error) {
if peeraddr == "" {
return SyncStats{}, fmt.Errorf("usage: accountsync <peer_multiaddr>")
Expand Down
16 changes: 13 additions & 3 deletions CLI/GRPC_Server.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,19 @@ func (s *CLIServer) AccountSync(ctx context.Context, req *pb.PeerRequest) (*pb.S
func (s *CLIServer) FirstSync(ctx context.Context, req *pb.FirstSyncRequest) (*pb.SyncStats, error) {
stats, err := s.handler.HandleFirstSync(req.Peer, req.Mode)
if err != nil {
return &pb.SyncStats{
Error: err.Error(),
}, nil
return &pb.SyncStats{Error: err.Error()}, nil
}
return &pb.SyncStats{
TimeTaken: int64(stats.TimeTaken.Seconds()),
MainState: convertDBState(stats.MainState),
AccountsState: convertDBState(stats.AccountsState),
}, nil
}

func (s *CLIServer) CatchUpSync(ctx context.Context, req *pb.CatchUpRequest) (*pb.SyncStats, error) {
stats, err := s.handler.HandleCatchUpSync(req.Peer, req.FromBlock)
if err != nil {
return &pb.SyncStats{Error: err.Error()}, nil
}
return &pb.SyncStats{
TimeTaken: int64(stats.TimeTaken.Seconds()),
Expand Down
9 changes: 9 additions & 0 deletions CLI/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ func (c *Client) FirstSync(peerAddr string, mode string) (*pb.SyncStats, error)
})
}

// CatchUpSync reconciles blocks [fromBlock..remoteTip] without Merkle bisection.
func (c *Client) CatchUpSync(peerAddr string, fromBlock uint64) (*pb.SyncStats, error) {
ctx := context.Background()
return c.conn.CatchUpSync(ctx, &pb.CatchUpRequest{
Peer: peerAddr,
FromBlock: fromBlock,
})
}

// GetDatabaseState returns the current database state
func (c *Client) GetDatabaseState() (*pb.DatabaseStates, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Expand Down
Loading
Loading