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

Add Backup DNS Seed for Dogecoin #1254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

UsaRandom
Copy link

Using backup dns seed, seed2.multidoge.org

see: dogecoinfoundation/libdogecoin#239

Was unable to connect to the dogecoin network using just seed.multidoge.org. This update fixes it.

Test example:


using NBitcoin;
using NBitcoin.Protocol;
using System;
using System.Linq;
using System.Threading;

public class Program
{
    public static void Main(string[] args)
    {
        // Define the Dogecoin mainnet network
        Network dogecoinMain = NBitcoin.Altcoins.Dogecoin.Instance.Mainnet;

        // Configure node connection settings
        var nodeSettings = new NodeConnectionParameters
        {
            UserAgent = "/nbitcoin-dogeseedtest:1.0.0/",
            Services = NodeServices.Network
        };

        // Start from the genesis block
        uint256 lastHash = dogecoinMain.GenesisHash;
        int height = 0;

        // Use NodesGroup for robust peer management
        using (var nodes = new NodesGroup(dogecoinMain, nodeSettings))
        {
            nodes.Connect(); // Connect to the network
            Console.WriteLine("Connected to Dogecoin network.");

            while (true)
            {
                try
                {
                    // Find a connected node
                    Node node = nodes.ConnectedNodes.FirstOrDefault();
                    if (node == null)
                    {
                        Console.WriteLine("No connected nodes. Waiting...");
                        Thread.Sleep(5000);
                        continue;
                    }

                    // Request block inventory
                    var getBlocks = new GetBlocksPayload
                    {
                        BlockLocators = new BlockLocator { Blocks = new List<uint256> { lastHash } }
                    };
                    node.SendMessage(getBlocks);

                    // Receive inventory with timeout
                    InvPayload inv = node.ReceiveMessage<InvPayload>(TimeSpan.FromSeconds(30));
                    if (inv.Inventory.Count == 0 || inv.Inventory[0].Type != InventoryType.MSG_BLOCK)
                    {
                        Console.WriteLine("No more blocks to process.");
                        break;
                    }

                    // Request the next block
                    var nextHash = inv.Inventory[0].Hash;
                    var getData = new GetDataPayload();
                    getData.Inventory.Add(new InventoryVector(InventoryType.MSG_BLOCK, nextHash));
                    node.SendMessage(getData);

                    // Receive the block
                    BlockPayload blockMessage = node.ReceiveMessage<BlockPayload>(TimeSpan.FromSeconds(30));
                    Block block = blockMessage.Object;

                    // Verify block sequence
                    if (block.Header.HashPrevBlock == lastHash)
                    {
                        height++;
                        lastHash = block.GetHash();
                        Console.WriteLine($"Block height: {height}");
                    }
                    else
                    {
                        Console.WriteLine($"Block out of order: {block.GetHash()}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex.Message}. Retrying in 5 seconds...");
                    Thread.Sleep(5000);
                }
            }
        }
    }
}

using backup dns seed, seed2.multidoge.org

see: dogecoinfoundation/libdogecoin#239
@UsaRandom UsaRandom changed the title Update Dogecoin.cs Add Backup DNS Seed for Dogecoin Feb 21, 2025
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.

1 participant