Skip to content

Conversation

@miladsoft
Copy link
Member

No description provided.

@miladsoft miladsoft requested review from DavidGershony and Copilot and removed request for Copilot March 24, 2025 08:04
/// Indicates if the response is successful.
/// </summary>
[ArrayProperty(2)]
public bool IsSuccess { get; init; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between this and the Accepted property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This IsSuccess property can be removed as it was an additional property added for testing purposes. It was redundant with the existing Accepted property which already provides the same functionality. The IsSuccess property has now been removed to simplify the codebase and avoid duplication.

using System.Threading.Tasks;
using Nostr.Client.Messages;

namespace Nostr.Client.NostrPow.Mining
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thing PoW is enough the whole namespace is nostr anyway

var tags = originalEvent.Tags ?? new NostrEventTags();

// Find the existing nonce tag if any
NostrEventTag? nonceTag = tags.FindFirstTag("nonce");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you use the "nonce" everywhere, can you add it to the const strings on the tag instead? or a local const...

// Set a current timestamp
miningEvent = new NostrEvent
{
Id = miningEvent.Id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, The id of a different event can't fit a new event

Kind = miningEvent.Kind,
Tags = miningEvent.Tags,
Content = miningEvent.Content,
Sig = miningEvent.Sig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sig can't fit an event with changed parameters

if (achievedDifficulty >= difficulty)
{
// We found a valid nonce, return the mined event
return candidateEvent.DeepClone(id, candidateEvent.Sig);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sig you are setting here is not valid, better to sign it again

/// <summary>
/// Interface for Nostr event miners
/// </summary>
public interface IMiner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need this

if (targetDifficulty.HasValue && targetDifficulty.Value < minDifficulty)
return false;

return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to check that the difficulty is greater than or equal to the target difficulty

/// </summary>
public static int CountLeadingZeroBitsInNibble(int nibble)
{
if (nibble >= 8) return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return return count + BitOperations.LeadingZeroCount((uint)nibble) - 24;

/// <summary>
/// Try to parse a hex character to its integer value
/// </summary>
private static bool TryParseHexDigit(char c, out int value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use int if we only look at the char value?

using System;
using System.Security.Cryptography;

namespace NostrDebug.Web.Pow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure, but why do we have a second implementation of the PoW instead of calling the implementation on the NostrEvent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants