Skip to content

Commit

Permalink
Merge pull request #104 from DiscreetNetwork/patch/view-fixes
Browse files Browse the repository at this point in the history
fix minor issue
  • Loading branch information
BrandonKoerner authored Feb 28, 2024
2 parents 7eb372c + e0e46c8 commit 8cc06b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
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

0 comments on commit 8cc06b5

Please sign in to comment.