Skip to content

Commit

Permalink
Check if a block already exists before write it
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Nov 13, 2019
1 parent feb6fca commit c8c6bdd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Libplanet/Store/DefaultStore.cs
Expand Up @@ -406,16 +406,18 @@ public override void PutBlock<T>(Block<T> block)
return;
}

UPath path = BlockPath(block.Hash);
if (_blocks.FileExists(path))
{
return;
}

foreach (Transaction<T> tx in block.Transactions)
{
PutTransaction(tx);
}

WriteContentAddressableFile(
_blocks,
BlockPath(block.Hash),
block.ToBencodex(true, false)
);
WriteContentAddressableFile(_blocks, path, block.ToBencodex(true, false));
_blockCache.AddOrUpdate(block.Hash, block.ToRawBlock(false, false));
}

Expand Down

0 comments on commit c8c6bdd

Please sign in to comment.