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

WIP - Prometheus Fork Development/Testing - V3.0.1 #12

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6301773
DNP Validation Tx Implementation - Phase 1
Dev-JamesR Jan 6, 2020
ea15ff8
DNP Validation Tx - Phase 1 Updates
Dev-JamesR Jan 6, 2020
24dcd89
POS/DNP Tx Validation Request/Response/Validation
Dev-JamesR Jan 7, 2020
eaddaa3
Phase 2 - Collateralized Node Validation System
Dev-JamesR Jan 8, 2020
2bf8a9d
Node TX Validation Updates - PeerSet Searching
Dev-JamesR Jan 8, 2020
823dc37
Collateralized Peer Groupings
Dev-JamesR Jan 8, 2020
0e0f837
DNP Sigs/Validation Updates
Dev-JamesR Jan 8, 2020
2127ebf
Phase 3 - Validation Tracking SC/TX Sig Validations
Dev-JamesR Jan 10, 2020
7b4210d
Enode ID Formatting/Sync Flags
Dev-JamesR Jan 11, 2020
01c110e
Validation/Signature Status Fix
Dev-JamesR Jan 11, 2020
ced296d
Prioritizing Validation Txs During Commit
Dev-JamesR Jan 13, 2020
3e197bd
Incoming TX Validation/State Access
Dev-JamesR Jan 13, 2020
b74dfe4
TX Sig/Validation Bug Fixes/Prioritization Fixes
Dev-JamesR Jan 13, 2020
9e8b12d
Prometheus Testing
Dev-JamesR Jan 14, 2020
9551535
Cleanup/Test Prep
Dev-JamesR Jan 17, 2020
d192c89
Code Reorg/DNP Cleanup
Dev-JamesR Jan 23, 2020
70ddda8
Peerset Length Bug Fix
Dev-JamesR Jan 24, 2020
5c6b807
DNP Sync Data RLP Encoding
Dev-JamesR Jan 27, 2020
6337634
Prmetheus Fork Prep
Dev-JamesR Feb 5, 2020
5653e99
Prometheus Prep
Dev-JamesR Feb 5, 2020
49b291d
Prometheus Prep
Dev-JamesR Feb 5, 2020
0cccec1
Node Validation State Access/Contract Access Update
Dev-JamesR Feb 11, 2020
9fd4018
Prometheus Testing Updates/Reorganization
Dev-JamesR Feb 18, 2020
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
8 changes: 4 additions & 4 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/core/nodeprotocol"
"github.com/ethereum/go-ethereum/dnp"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/debug"
Expand Down Expand Up @@ -360,9 +360,9 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}
if ctx.GlobalIsSet(utils.NodeFlag.Name) {
nodeprotocol.SetProtocolFlag(true)
dnp.SetProtocolFlag(true)
} else {
nodeprotocol.SetProtocolFlag(false)
dnp.SetProtocolFlag(false)
}
nodeprotocol.SetActiveNode(stack)
dnp.SetActiveNode(stack)
}
32 changes: 22 additions & 10 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/nodeprotocol"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/dnp"
"github.com/ethereum/go-ethereum/dnpdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -585,25 +586,25 @@ func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header
var currentNodeAddress common.Address

// Get total current node count from contract and save to caching addresses
currentNodeCount := nodeprotocol.GetNodeCount(state, nodeType.ContractAddress)
currentNodeCount := dnpdb.GetNodeCount(state, nodeType.ContractAddress)
if currentNodeCount > 0 {
// Determine next reward candidate and save data to caching addresses
currentNodeId, currentNodeIp, currentNodeAddress = nodeprotocol.GetNodeCandidate(state, rewardHeader.Hash(), currentNodeCount, nodeType.ContractAddress)
currentNodeId, currentNodeIp,_, currentNodeAddress = dnpdb.GetNodeCandidate(state, rewardHeader.Hash(), currentNodeCount, nodeType.ContractAddress)
} else {
currentNodeId = "None"
currentNodeIp = "None"
currentNodeAddress = common.HexToAddress("0x0")
}

nodeCount := nodeprotocol.UpdateNodeCount(state, currentNodeCount, nodeType.CountCachingAddresses)
nodeId, nodeIp, nodeAddress, nodeIdString, nodeIpString := nodeprotocol.UpdateNodeCandidate(state, currentNodeId, currentNodeIp, currentNodeAddress, nodeType.NodeIdCachingAddresses, nodeType.NodeIpCachingAddresses, nodeType.NodeAddressCachingAddresses)
nodeCount := dnpdb.UpdateNodeCount(state, currentNodeCount, nodeType.CountCachingAddresses)
nodeId, nodeIp, nodeAddress, nodeIdString, nodeIpString := dnpdb.UpdateNodeCandidate(state, currentNodeId, currentNodeIp, currentNodeAddress, nodeType.NodeIdCachingAddresses, nodeType.NodeIpCachingAddresses, nodeType.NodeAddressCachingAddresses)

nodeIdArray = append(nodeIdArray, nodeIdString)
nodeIpArray = append(nodeIpArray, nodeIpString)

if nodeCount > 0 {
totalNodeCount += nodeCount
if nodeprotocol.CheckNodeStatus(nodeType.Name, nodeId, nodeIp, payoutHeader.Hash(), payoutHeader.Number.Uint64()) {
if dnp.CheckNodeStatus(nodeType.Name, nodeId, nodeIp, payoutHeader.Hash(), payoutHeader.Number.Uint64()) {
log.Debug("Node Status Verified", "Node Type", nodeType.Name, "ID", nodeId, "IP", nodeIp)
nodeAddresses = append(nodeAddresses, nodeAddress)
} else {
Expand All @@ -617,19 +618,19 @@ func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header
}

// Save node remainders
nodeRemainder := nodeprotocol.GetNodeRemainder(state, uint64(nodeCount), nodeType.RemainderAddress)
nodeRemainder := dnpdb.GetNodeRemainder(state, uint64(nodeCount), nodeType.RemainderAddress)
nodeRemainders = append(nodeRemainders, nodeRemainder)
}

//Checking for active node
nodeprotocol.CheckActiveNode(totalNodeCount, header.Hash(), header.Number.Int64())
dnp.CheckActiveNode(totalNodeCount, header.Hash(), header.Number.Int64())

}
params.NodeIdArray = nodeIdArray
params.NodeIpArray = nodeIpArray

// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(chain.Config(), state, header, uncles, nodeAddresses, nodeRemainders)
accumulateRewards(chain.Config(), state, header, uncles, txs, nodeAddresses, nodeRemainders)
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))

// Header seems complete, assemble into a block and return
Expand Down Expand Up @@ -668,7 +669,7 @@ var (
// AccumulateRewards credits the coinbase of the given block with the mining
// reward. The total reward consists of the static block reward and rewards for
// included uncles. The coinbase of each uncle block is also rewarded.
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header, nodeAddresses []common.Address, nodeRemainders []*big.Int) {
func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header *types.Header, uncles []*types.Header, txs []*types.Transaction, nodeAddresses []common.Address, nodeRemainders []*big.Int) {
var blockReward = minerBlockReward // Set miner reward base
var masternodeReward = masternodeBlockReward // Set masternode reward
var developmentReward = developmentBlockReward // Set development reward
Expand Down Expand Up @@ -735,6 +736,17 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
state.AddBalance(common.HexToAddress("0xB69B9216B5089Dc3881A4E38f691e9B6943DFA11"), developmentReward)
// Node Rewards via consensus
if header.Number.Int64() > params.NodeProtocolBlock {
// Disburse any potential node protocol priority tx rewards here
if config.IsPrometheus(header.Number) {
priorityTxReward := new(big.Int)
priorityTxReward.Div(blockReward, big.NewInt(100))
for _, tx := range txs {
if dnp.CheckValidNodeProtocolTx(tx) {
// Reward miner for mining priority node validation txs
state.AddBalance(header.Coinbase, priorityTxReward)
}
}
}
if len(nodeAddresses) == len(params.NodeTypes) {
// Iterate over node types to disburse node rewards and calculated remainders
for i := 0; i < len(params.NodeTypes); i++ {
Expand Down
83 changes: 30 additions & 53 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"sync"
"sync/atomic"
"time"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock"
Expand All @@ -36,9 +35,10 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/nodeprotocolmessaging"
"github.com/ethereum/go-ethereum/core/nodeprotocol"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/dnp"
"github.com/ethereum/go-ethereum/dnpdb"
"github.com/ethereum/go-ethereum/dnpbridge"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -210,7 +210,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
go bc.update()

// Set blockchain state for node protocol access
nodeprotocolmessaging.SetBlockchain(bc)
dnpbridge.SetBlockchain(bc)

return bc, nil
}
Expand Down Expand Up @@ -513,34 +513,29 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
// Note, this function assumes that the `mu` mutex is held!
func (bc *BlockChain) insert(block *types.Block) {
// Check for next node up for reward
if block.Header().Number.Int64() > params.NodeProtocolBlock && !nodeprotocolmessaging.GetSyncStatus() {
if block.Header().Number.Int64() > params.NodeProtocolBlock && !dnpbridge.Syncing() && bc.chainConfig.IsPrometheus(block.Header().Number) {
rewardBlock := bc.GetBlockByNumber(block.NumberU64() - 100)
if rewardBlock != nil {
for _, nodeType := range params.NodeTypes {
// Get current state snapshot
state, err := bc.State()
if err == nil {
nodeCount := nodeprotocol.GetNodeCount(state, nodeType.ContractAddress)
// Get current state snapshot
state, err := bc.State()
if err == nil {
if dnpbridge.GetPeerCount() < params.MinCollateralizedPeerGroup {
nodes := dnpdb.GetCollateralizedNodes(state, rewardBlock.Header().Hash())
for _,node := range nodes {
log.Debug("Direct Connection To Collateralized Node Initiated", "Id", node.Id)
dnpbridge.DirectConnectToNode(node.Id, node.Ip, node.Port)
}
}
for _, nodeType := range params.NodeTypes {
nodeCount := dnpdb.GetNodeCount(state, nodeType.ContractAddress)
if nodeCount > 0 {
// Determine next reward candidate based on statedb
nodeId, nodeIp, _ := nodeprotocol.GetNodeCandidate(state, rewardBlock.Hash(), nodeCount, nodeType.ContractAddress)
rewardBlockNumber := strconv.FormatUint(rewardBlock.NumberU64(), 10)

selfId := nodeprotocol.GetNodeId(nodeprotocol.ActiveNode().Server().Self())

if nodeprotocolmessaging.CheckPeerSet(nodeId, nodeIp) {
log.Debug("Peer Identified as Reward Candidate - Broadcasting Evidence of Node Activity", "Type", nodeType.Name, "ID", nodeId)
var data = []string{nodeType.Name, nodeId, nodeIp, rewardBlock.Hash().String(), rewardBlockNumber}
nodeprotocol.UpdateNodeProtocolData(nodeType.Name, nodeId, nodeIp, selfId, nodeprotocolmessaging.GetPeerCount(), rewardBlock.Hash(), rewardBlock.NumberU64(), false)
nodeprotocolmessaging.SendNodeProtocolData(data)
}
previousRewardBlock := bc.GetBlockByHash(rewardBlock.ParentHash())
if previousRewardBlock != nil && !nodeprotocol.CheckUpToDate(nodeType.Name, previousRewardBlock.Hash(), previousRewardBlock.NumberU64()) {
log.Debug("Requesting Previous Reward Block Candidate Data", "Type", nodeType.Name)
previousRewardBlockNumber := strconv.FormatUint(previousRewardBlock.NumberU64(), 10)
var data = []string{nodeType.Name, previousRewardBlock.Hash().String(), previousRewardBlockNumber}
nodeprotocolmessaging.RequestNodeProtocolData(data)
}
selfEnodeId := dnp.GetNodeEnodeId(dnp.ActiveNode().Server().Self())
nodeCandidateId,_,_,_ := dnpdb.GetNodeCandidate(state, rewardBlock.Header().Hash(), nodeCount, nodeType.ContractAddress)
if common.HexToHash(selfEnodeId) == common.HexToHash(nodeCandidateId) {
log.Debug("Local Node Determined To Be Part Of Upcoming Reward - Requesting Validations", "Number", rewardBlock.NumberU64())
dnpbridge.RequestNodeProtocolValidations(state, selfEnodeId, rewardBlock.Header().Hash(), rewardBlock.NumberU64())
break
}
}
}
}
Expand Down Expand Up @@ -1258,7 +1253,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
}
// Validate the state using the default validator
if err := bc.Validator().ValidateState(block, parent, state, receipts, usedGas); err != nil {
if block.Number().Int64() > params.NodeProtocolBlock {
if block.Number().Int64() > params.NodeProtocolBlock && !bc.chainConfig.IsPrometheus(block.Number()) {
if bc.rotateBlockData(block) {
goto Start
}
Expand All @@ -1281,7 +1276,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
return it.index, events, coalescedLogs, err
}

if block.Number().Int64() > params.NodeProtocolBlock {
if block.Number().Int64() > params.NodeProtocolBlock && bc.chainConfig.IsPrometheus(block.Number()) {
bc.checkBlockDataRotation(block)
}

Expand Down Expand Up @@ -1658,38 +1653,20 @@ func (bc *BlockChain) addBadBlock(block *types.Block) {
// rotateBlockData initiates the node reward solver during sync
func (bc *BlockChain) rotateBlockData(block *types.Block) bool {
rewardBlock := bc.GetBlockByNumber(block.Number().Uint64() - 105)
nodeprotocol.SetHoldBlockNumber(rewardBlock.Number().Uint64())
if nodeprotocol.BadBlockRotation(params.NodeIdArray, params.NodeIpArray, rewardBlock.Hash()) {
dnp.SetHoldBlockNumber(rewardBlock.Number().Uint64())
if dnp.BadBlockRotation(params.NodeIdArray, params.NodeIpArray, rewardBlock.Hash()) {
return true
}
return false
}

// checkBlockDataRotation validates the node reward solver and broadcasts
func (bc *BlockChain) checkBlockDataRotation(block *types.Block) {
//rewardBlock := bc.GetBlockByNumber(block.Number().Uint64() - 105)
//rewardBlockNumber := strconv.FormatUint(rewardBlock.NumberU64(), 10)
//var holdBlockCount int64
if nodeprotocol.HoldBlockCount > 0 && nodeprotocol.HoldBlockNumber != "" {
// holdBlockCount = nodeprotocol.HoldBlockCount - 1
nodeprotocol.ResetHoldBlockCount()
if dnp.HoldBlockCount > 0 && dnp.HoldBlockNumber != "" {
dnp.ResetHoldBlockCount()
} else {
return
}

/*
// Determine binary string for node reward block solution
binaryString := strconv.FormatInt(holdBlockCount, 2)
for len(binaryString) < 4 {
binaryString = "0" + binaryString
}
binaryArray := strings.Split(binaryString, "")
for key, nodeType := range params.NodeTypes {
if binaryArray[key] == "1" {
var data = []string{nodeType.Name, params.NodeIdArray[key], params.NodeIpArray[key], rewardBlock.Hash().String(), rewardBlockNumber}
nodeprotocolmessaging.SendNodeProtocolData(data)
}
}*/
}

// reportBlock logs a bad block error.
Expand Down
5 changes: 5 additions & 0 deletions core/dnp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"0x0000000000000000000000000000000000000000000000000000000000001111": 1101,
"0x0000000000000000000000000000000000000000000000000000000000002222": 1001,
"0x0000000000000000000000000000000000000000000000000000000000003333": 1011
}
87 changes: 87 additions & 0 deletions core/mkdnpdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2017 The go-ethereum Authors
// Copyright 2020 by The etho.black Development Team
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// +build none

/*

The mkdnpalloc tool creates the RPL encoded dnp sync data for future use with dnp node syncing

go run mkdnpalloc.go dnp.json

*/
package main

import (
"encoding/json"
"fmt"
"math/big"
"os"
"sort"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
)

type allocItem struct{ Hash, Data *big.Int }

type allocList []allocItem

var dnpData map[common.Hash]int64

func (a allocList) Len() int { return len(a) }
func (a allocList) Less(i, j int) bool { return a[i].Hash.Cmp(a[j].Hash) < 0 }
func (a allocList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func makelist(d map[common.Hash]int64) allocList {
a := make(allocList, 0, len(d))
for key, data := range d {
bigHash := new(big.Int).SetBytes(key.Bytes())
bigData := big.NewInt(data)
a = append(a, allocItem{bigHash, bigData})
}
sort.Sort(a)
return a
}

func makealloc(d map[common.Hash]int64) string {
a := makelist(d)
data, err := rlp.EncodeToBytes(a)
if err != nil {
panic(err)
}
return strconv.QuoteToASCII(string(data))
}

func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "Usage: mkalloc genesis.json")
os.Exit(1)
}

dnpData := make(map[common.Hash]int64)
file, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
if err := json.NewDecoder(file).Decode(&dnpData); err != nil {
panic(err)
}
fmt.Println(dnpData)
fmt.Println("const allocData =", makealloc(dnpData))
}
Loading