Exemplo n.º 1
0
        internal static ulong GetBlockReward(NetworkConfig Globals, byte MajorVersion, uint MedianSize,
                                             uint BlockSize, ulong AlreadyGeneratedUnits, ulong Fee, out ulong EmissionChange)
        {
            // Check if we are at unit capacity
            if (AlreadyGeneratedUnits <= Globals.CURRENCY_TOTAL_SUPPLY)
            {
                throw new Exception("Total units has been reached");
            }

            // Calculate base reward
            ulong BaseReward = Globals.CURRENCY_GENESIS_REWARD;

            if (AlreadyGeneratedUnits > 0)
            {
                BaseReward = (Globals.CURRENCY_TOTAL_SUPPLY - AlreadyGeneratedUnits) >> Globals.CURRENCY_EMISSION_FACTOR;
            }

            // Calculate reward zone

            // TODO - define these in a more appropriate spot (in core they are in the config)
            uint BlockGrantedFullRewardZone = 10_000;

            if (MajorVersion == Constants.BLOCK_MAJOR_VERSION_2)
            {
                BlockGrantedFullRewardZone = 20_000;
            }
            else if (MajorVersion >= Constants.BLOCK_MAJOR_VERSION_3)
            {
                BlockGrantedFullRewardZone = 100_000;
            }
            MedianSize = Math.Max(MedianSize, BlockGrantedFullRewardZone);

            // Calculate penalties
            ulong PenalizedBaseReward = GetPenalizedAmount(BaseReward, MedianSize, BlockSize);
            ulong PenalizedFee        = Fee;

            if (MajorVersion >= Constants.BLOCK_MAJOR_VERSION_2)
            {
                PenalizedFee = GetPenalizedAmount(Fee, MedianSize, BlockSize);
            }

            // Calculate emission change
            EmissionChange = PenalizedBaseReward - (Fee - PenalizedFee);

            // Return reward result
            return(PenalizedBaseReward + PenalizedFee);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes this node with the specified network configuration
        /// </summary>
        /// <param name="Configuration">A class containing all global information this node needs to operate</param>
        public Node(NetworkConfig Configuration)
        {
            // Assign configuration
            Globals = Configuration;

            // Generate identifier
            Id = SecureRandom.Integer <ulong>();

            // Setup and start logger
            Logger = new Logger()
            {
                LogFile        = Globals.LOG_FILE,
                LogLevel       = Globals.LOG_LEVEL,
                CustomPrefix   = Globals.CUSTOM_PREFIX,
                ImportantColor = Globals.IMPORTANT_COLOR,
                InfoColor      = Globals.INFO_COLOR,
                ErrorColor     = Globals.ERROR_COLOR,
                WarningColor   = Globals.WARNING_COLOR,
                DebugColor     = Globals.DEBUG_COLOR
            };

            // Setup blockchain cache
            Blockchain = new BlockchainCache(Globals)
            {
                Logger = Logger
            };

            // Create our P2P server
            P2pServer = new P2pServer(Globals.P2P_WORKERS, Globals.P2P_MAX_PEER_CONNECTIONS)
            {
                ConnectionTimeout = Globals.P2P_CONNECTION_TIMEOUT
            };

            // Setup our API server
            ApiServer = new ApiServer(Globals.API_WORKERS, Globals.API_PASSWORD)
            {
                Logger = Logger
            };

            // Setup done, set node to stopped
            Stopped = true;
        }
Exemplo n.º 3
0
 // Initializes a new blockchain storage
 internal BlockchainCache(NetworkConfig Config)
 {
     // Assign network config
     Globals = Config;
 }