Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix minor issue #104

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions Discreet/DB/AlreadyPresentException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Discreet.Common.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discreet.DB
{
public class AlreadyPresentException : VerifyException
{
public AlreadyPresentException(string msg) : base("Discreet.Coin.Verify: " + msg) { }

public AlreadyPresentException(string type, string msg) : base("Discreet.Coin." + type + ".Verify: " + msg) { }

public AlreadyPresentException(string type, string vertype, string msg) : base("Discreet.Coin." + type + "Verify" + vertype + ": " + msg) { }
}
}
2 changes: 1 addition & 1 deletion Discreet/DB/ValidationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private Exception validate(bool many = false)
if (!block.Hash().Equals(block.Header.BlockHash)) return new VerifyException("Block", $"Block hash in header does not match calculated block hash");
if (blockBuffer.BlockExists(block.Header.BlockHash))
{
return new VerifyException("Block", $"Block already present");
return new AlreadyPresentException("Block", $"Block already present");
}
if (block.Transactions == null || block.Transactions.Length == 0) return new VerifyException("Block", "Block contains no transactions");
if (block.Header.NumTXs != block.Transactions.Length) return new VerifyException("Block", $"Block tx mismatch: expected {block.Header.NumTXs}; got {block.Transactions.Length}");
Expand Down
6 changes: 5 additions & 1 deletion Discreet/Daemon/Daemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ public async Task<bool> Start()
{
var vcache = new DB.ValidationCache(messageCache.GetAllCachedBlocks(_beginHeight, _newHeight));
(exc, _beginHeight, var goodBlocks, var reget) = vcache.ValidateReturnFailures();

if (exc is AlreadyPresentException apex)
{
// ignore this
exc = null;
}
if (exc != null && reget != null)
{
// first, flush valid blocks
Expand Down
4 changes: 2 additions & 2 deletions Discreet/Network/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public async Task HandleGetBlocks(GetBlocksPacket p, IPEndPoint senderEndpoint)

public async Task HandleGetTxs(GetTransactionsPacket p, IPEndPoint senderEndpoint)
{
DB.DataView dataView = DB.DataView.GetView();
IView dataView = BlockBuffer.Instance;

List<FullTransaction> txs = new();
List<InventoryVector> notFound = new();
Expand Down Expand Up @@ -1386,7 +1386,7 @@ public async Task HandleBlocks(BlocksPacket p, Peerbloom.Connection conn)

public async Task HandleGetHeaders(GetHeadersPacket p, Peerbloom.Connection conn)
{
DB.DataView dataView = DB.DataView.GetView();
IView dataView = BlockBuffer.Instance;

List<BlockHeader> headers = new();
List<InventoryVector> notFound = new();
Expand Down
Loading