Skip to content

Commit

Permalink
Release78: Mining and other minor bugs fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDero committed May 23, 2022
1 parent b660adf commit db7eba4
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 44 deletions.
4 changes: 2 additions & 2 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (bl *Block) GetTimestamp() time.Time {
func (bl Block) String() string {
r := new(strings.Builder)
fmt.Fprintf(r, "BLID:%s\n", bl.GetHash())
fmt.Fprintf(r, "Major version:%d Minor version: %d", bl.Major_Version, bl.Minor_Version)
fmt.Fprintf(r, "Height:%d\n", bl.Height)
fmt.Fprintf(r, "Major version:%d Minor version: %d ", bl.Major_Version, bl.Minor_Version)
fmt.Fprintf(r, "Height:%d ", bl.Height)
fmt.Fprintf(r, "Timestamp:%d (%s)\n", bl.Timestamp, bl.GetTimestamp())
for i := range bl.Tips {
fmt.Fprintf(r, "Past %d:%s\n", i, bl.Tips[i])
Expand Down
7 changes: 4 additions & 3 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func Blockchain_Start(params map[string]interface{}) (*Blockchain, error) {
chain.RPC_NotifyHeightChanged = sync.NewCond(&sync.Mutex{}) // used by dero daemon to notify all websockets that chain height has changed
chain.RPC_NotifyNewMiniBlock = sync.NewCond(&sync.Mutex{}) // used by dero daemon to notify all websockets that new miniblock has arrived

if !chain.Store.IsBalancesIntialized() {
if chain.Store.Topo_store.Count() == 0 && !chain.Store.IsBalancesIntialized() {
logger.Info("Genesis block not in store, add it now")
var complete_block block.Complete_Block
bl := Generate_Genesis_Block()
Expand All @@ -208,7 +208,8 @@ func Blockchain_Start(params map[string]interface{}) (*Blockchain, error) {
try_again:
version, err := chain.ReadBlockSnapshotVersion(chain.Get_Top_ID())
if err != nil {
panic(err)
chain.Rewind_Chain(1) // rewind 1 block
goto try_again
}
// this case happens when chain syncs from rsync and if rsync takes more time than block_time
// basically this can also be fixed, if topo.map file is renamed to name starting with 'a'
Expand Down Expand Up @@ -455,7 +456,7 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro
}

} else {

logger.V(1).Error(err, "Block rejected by chain", "BLID", block_hash, "bl", fmt.Sprintf("%x", bl.Serialize()), "stack", debug.Stack())
logger.V(1).Error(err, "Block rejected by chain", "BLID", block_hash)
}
}()
Expand Down
10 changes: 10 additions & 0 deletions blockchain/miniblocks_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func Verify_MiniBlocks(bl block.Block) (err error) {
return
}

collection := block.CreateMiniBlockCollection()

// check whether the genesis blocks are all equal
for _, mbl := range bl.MiniBlocks {

Expand Down Expand Up @@ -112,6 +114,14 @@ func Verify_MiniBlocks(bl block.Block) (err error) {
} else {
panic("we only support 1 tips")
}*/
collection.InsertMiniBlock(mbl)
}

if bl.Height >= 399000 { // soft HF
if uint64(collection.Count()) != uint64((config.BLOCK_TIME - config.MINIBLOCK_HIGHDIFF)) {
err = fmt.Errorf("block contains invalid number of miniblocks count %d expected %d\n", collection.Count(), uint64((config.BLOCK_TIME - config.MINIBLOCK_HIGHDIFF)))
return
}
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/dero-wallet-cli/easymenu_post_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
}
}

logger.Info("Destination port is integreted in address.", "dst port", a.Arguments.Value(rpc.RPC_DESTINATION_PORT, rpc.DataUint64).(uint64))
logger.Info("Destination port is integrated in address.", "dst port", a.Arguments.Value(rpc.RPC_DESTINATION_PORT, rpc.DataUint64).(uint64))

if a.Arguments.Has(rpc.RPC_COMMENT, rpc.DataString) { // but only it is present
logger.Info("Integrated Message", "comment", a.Arguments.Value(rpc.RPC_COMMENT, rpc.DataString))
Expand Down Expand Up @@ -405,7 +405,7 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
}
// if user provided an integrated address donot ask him payment id
if a.IsIntegratedAddress() {
globals.Logger.Infof("Payment ID is integreted in address ID:%x", a.PaymentID)
globals.Logger.Infof("Payment ID is integrated in address ID:%x", a.PaymentID)
}
if ConfirmYesNoDefaultNo(l, "Confirm Transaction to send entire balance (y/N)") {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dero-wallet-cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func handle_prompt_command(l *readline.Instance, line string) {
for i := range addr_list {
if addr_list[i].IsIntegratedAddress() {
payment_id_integrated = true
logger.Info("Payment ID is integreted in address ID:%x", addr_list[i].PaymentID)
logger.Info("Payment ID is integrated in address ID:%x", addr_list[i].PaymentID)
}
}
Expand Down
59 changes: 47 additions & 12 deletions cmd/derod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ restart_loop:
logger.Info("\n")

}

case command == "regpool_print":
chain.Regpool.Regpool_Print()

Expand Down Expand Up @@ -724,8 +723,24 @@ restart_loop:
bl, err := chain.Load_BL_FROM_ID(hash)
if err != nil {
fmt.Printf("Err %s\n", err)
continue
}
fmt.Printf("%s\n", bl.String())

header, _ := derodrpc.GetBlockHeader(chain, hash)
fmt.Fprintf(os.Stdout, "BLID:%s\n", bl.GetHash())
fmt.Fprintf(os.Stdout, "Major version:%d Minor version: %d ", bl.Major_Version, bl.Minor_Version)
fmt.Fprintf(os.Stdout, "Height:%d ", bl.Height)
fmt.Fprintf(os.Stdout, "Timestamp:%d (%s)\n", bl.Timestamp, bl.GetTimestamp())
for i := range bl.Tips {
fmt.Fprintf(os.Stdout, "Past %d:%s\n", i, bl.Tips[i])
}
for i, mbl := range bl.MiniBlocks {
fmt.Fprintf(os.Stdout, "Mini %d:%s %s\n", i, mbl, header.Miners[i])
}
for i, txid := range bl.Tx_hashes {
fmt.Fprintf(os.Stdout, "tx %d:%s\n", i, txid)
}

fmt.Printf("difficulty: %s\n", chain.Load_Block_Difficulty(hash).String())
fmt.Printf("TopoHeight: %d\n", chain.Load_Block_Topological_order(hash))

Expand Down Expand Up @@ -836,34 +851,54 @@ restart_loop:

supply = (config.PREMINE + blockchain.CalcBlockReward(uint64(chain.Get_Height()))*uint64(chain.Get_Height())) // valid for few years

hostname, _ := os.Hostname()
fmt.Printf("STATUS MENU for DERO HE Node - Hostname: %s\n\n", hostname)
fmt.Printf("Hostname: %s - Uptime: %s\n", hostname, time.Now().Sub(globals.StartTime).Round(time.Second).String())
fmt.Printf("Uptime Since: %s\n\n", globals.StartTime.Format(time.RFC1123))

fmt.Printf("Network %s Height %d NW Hashrate %0.03f MH/sec Peers %d inc, %d out MEMPOOL size %d REGPOOL %d Total Supply %s DERO \n", globals.Config.Name, chain.Get_Height(), float64(chain.Get_Network_HashRate())/1000000.0, inc, out, mempool_tx_count, regpool_tx_count, globals.FormatMoney(supply))

tips := chain.Get_TIPS()
fmt.Printf("Tips ")
for _, tip := range tips {
fmt.Printf(" %s(%d)", tip, chain.Load_Height_for_BL_ID(tip))
}

if chain.LocatePruneTopo() >= 1 {
fmt.Printf("Chain is pruned till %d\n", chain.LocatePruneTopo())
fmt.Printf("\nChain is pruned till %d\n", chain.LocatePruneTopo())
} else {
fmt.Printf("Chain is in full mode.\n")
fmt.Printf("\nChain is in full mode.\n")
}
fmt.Printf("Integrator address %s\n", chain.IntegratorAddress().String())
fmt.Printf("UTC time %s (as per system clock) \n", time.Now().UTC())
fmt.Printf("UTC time %s (offset %s) (as per daemon) should be close to 0\n", globals.Time().UTC(), time.Now().Sub(globals.Time()))
fmt.Printf("Local time %s (as per system clock) \n", time.Now())
fmt.Printf("Local time %s (offset %s) (as per daemon) should be close to 0\n", globals.Time(), time.Now().Sub(globals.Time()))

fmt.Print("\nPeer Stats:\n")
fmt.Printf("\tPeer ID: %d\n", p2p.GetPeerID())

blocksMined := (derodrpc.CountMinisAccepted + derodrpc.CountBlocks) - derodrpc.CountMinisRejected
fmt.Print("\nMining Stats:\n")
fmt.Printf("\tBlock Minted: %d (MB+IB)\n", (derodrpc.CountMinisAccepted+derodrpc.CountBlocks)-derodrpc.CountMinisRejected)
if blocksMined > 0 {
fmt.Printf("\tMinting Velocity: %.4f MB/h\t%.4f MB/d (since uptime)\n", float64(float64(derodrpc.CountMinisAccepted)/time.Now().Sub(globals.StartTime).Seconds())*3600,
float64(float64(derodrpc.CountMinisAccepted)/time.Now().Sub(globals.StartTime).Seconds())*3600*24)
} else {
fmt.Print("\tMinting Velocity: 0.0000 MB/h\t0.0000MB/d (since uptime)\n")
}
//if derodrpc.CountMiners() > 0 { // only give info if we have a miner connected
fmt.Printf("MB:%d MBR:%d IB:%d\n", derodrpc.CountMinisAccepted, derodrpc.CountMinisRejected, derodrpc.CountBlocks)
fmt.Printf("MB %.02f%%(1hr) %.05f%%(1d) %.06f%%(7d) (Moving average %%, will be 0 if no miniblock found)\n", derodrpc.HashrateEstimatePercent_1hr(), derodrpc.HashrateEstimatePercent_1day(), derodrpc.HashrateEstimatePercent_7day())
fmt.Printf("\tMB:%d MBR:%d IB:%d\n", derodrpc.CountMinisAccepted, derodrpc.CountMinisRejected, derodrpc.CountBlocks)
fmt.Printf("\tMB %.02f%%(1hr)\t%.05f%%(1d)\t%.06f%%(7d)\t(Moving average %%, will be 0 if no miniblock found)\n", derodrpc.HashrateEstimatePercent_1hr(), derodrpc.HashrateEstimatePercent_1day(), derodrpc.HashrateEstimatePercent_7day())
mh_1hr := uint64((float64(chain.Get_Network_HashRate()) * derodrpc.HashrateEstimatePercent_1hr()) / 100)
mh_1d := uint64((float64(chain.Get_Network_HashRate()) * derodrpc.HashrateEstimatePercent_1day()) / 100)
mh_7d := uint64((float64(chain.Get_Network_HashRate()) * derodrpc.HashrateEstimatePercent_7day()) / 100)
fmt.Printf("Avg Mining HR %s(1hr) %s(1d) %s(7d)\n", hashratetostring(mh_1hr), hashratetostring(mh_1d), hashratetostring(mh_7d))
fmt.Printf("\tAvg Mining HR %s(1hr)\t%s(1d)\t%s(7d)\n", hashratetostring(mh_1hr), hashratetostring(mh_1d), hashratetostring(mh_7d))
//}

tips := chain.Get_TIPS()
fmt.Printf("Tips ")
for _, tip := range tips {
fmt.Printf(" %s(%d)", tip, chain.Load_Height_for_BL_ID(tip))
}
fmt.Printf("\n")
fmt.Printf("Current Block Reward: %s\n", globals.FormatMoney(blockchain.CalcBlockReward(uint64(chain.Get_Height()))))
fmt.Printf("\n")

// print hardfork status on second line
hf_state, _, _, threshold, version, votes, window := chain.Get_HF_info()
Expand Down
30 changes: 30 additions & 0 deletions cmd/derod/rpc/blockheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package rpc
//import "fmt"
import "github.com/deroproject/derohe/cryptography/crypto"
import "github.com/deroproject/derohe/rpc"
import "github.com/deroproject/derohe/config"
import "github.com/deroproject/derohe/globals"
import "github.com/deroproject/derohe/blockchain"

// this function is only used by the RPC and is not used by the core and should be moved to RPC interface
Expand Down Expand Up @@ -54,5 +56,33 @@ func GetBlockHeader(chain *blockchain.Blockchain, hash crypto.Hash) (result rpc.
//result.Prev_Hash = bl.Prev_Hash.String()
result.Timestamp = bl.Timestamp

if toporecord, err1 := chain.Store.Topo_store.Read(result.Height); err1 == nil { // we must now fill in compressed ring members
if ss, err1 := chain.Store.Balance_store.LoadSnapshot(toporecord.State_Version); err1 == nil {
if balance_tree, err1 := ss.GetTree(config.BALANCE_TREE); err1 == nil {

for _, mbl := range bl.MiniBlocks {
bits, key, _, err1 := balance_tree.GetKeyValueFromHash(mbl.KeyHash[0:16])
if err1 != nil || bits >= 120 {
continue
}
if addr, err1 := rpc.NewAddressFromCompressedKeys(key); err1 == nil {
addr.Mainnet = globals.IsMainnet()
result.Miners = append(result.Miners, addr.String())
}
}
}
}
}
for len(bl.MiniBlocks) > len(result.Miners) {
result.Miners = append(result.Miners, "unknown")
}

{ // last miniblock goes to intgretor
if addr, err1 := rpc.NewAddressFromCompressedKeys(bl.Miner_TX.MinerAddress[:]); err1 == nil && len(result.Miners) >= 10 {
addr.Mainnet = globals.IsMainnet()
result.Miners[9] = addr.String()
}
}

return
}
17 changes: 17 additions & 0 deletions cmd/derod/rpc/rpc_dero_getinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package rpc

import "fmt"
import "time"
import "context"
import "runtime/debug"
import "github.com/deroproject/derohe/config"
import "github.com/deroproject/derohe/globals"
import "github.com/deroproject/derohe/rpc"
import "github.com/deroproject/derohe/p2p"

import "github.com/deroproject/derohe/blockchain"

Expand Down Expand Up @@ -87,5 +89,20 @@ func GetInfo(ctx context.Context) (result rpc.GetInfo_Result, err error) {
result.Network = "Simulator"
}

in, out := p2p.Peer_Direction_Count()
result.Incoming_connections_count = in
result.Outgoing_connections_count = out
result.Miners = CountMiners()
result.Miniblocks_In_Memory = chain.MiniBlocks.Count()
result.CountMinisRejected = CountMinisRejected
result.CountMinisAccepted = CountMinisAccepted
result.CountBlocks = CountBlocks
result.Mining_Velocity = float64(float64((CountMinisAccepted+CountBlocks)-CountMinisRejected)/time.Now().Sub(globals.StartTime).Seconds()) * 3600
result.Uptime = uint64(time.Now().Sub(globals.StartTime).Seconds())

result.HashrateEstimatePercent_1hr = uint64((float64(chain.Get_Network_HashRate()) * HashrateEstimatePercent_1hr()) / 100)
result.HashrateEstimatePercent_1day = uint64((float64(chain.Get_Network_HashRate()) * HashrateEstimatePercent_1day()) / 100)
result.HashrateEstimatePercent_7day = uint64((float64(chain.Get_Network_HashRate()) * HashrateEstimatePercent_7day()) / 100)

return result, nil
}
1 change: 1 addition & 0 deletions cmd/webwallet/webwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func register_wallet_callbacks() {
error_message = "success"
Local_wallet_instance = w
Local_wallet_instance.SetDaemonAddress(daemon_address)
Local_wallet_instance.SetNetwork(globals.IsMainnet()) // set mainnet/testnet
} else {
error_message = err.Error()
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ var Testnet = CHAIN_CONFIG{Name: "testnet", // testnet will always have last 3 b
}

// mainnet has a remote daemon node, which can be used be default, if user provides a --remote flag
const REMOTE_DAEMON = "185.132.176.174" // "https://rwallet.dero.live"
const REMOTE_DAEMON = "89.38.99.117" // "https://rwallet.dero.live"
1 change: 0 additions & 1 deletion config/seed_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package config
var Mainnet_seed_nodes = []string{
"89.38.99.117:8443",
"45.82.66.54:8080",
"185.107.69.12:11011",
"89.38.97.110:11011",
"45.82.66.55:11011",
}
Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ import "github.com/blang/semver/v4"

// right now it has to be manually changed
// do we need to include git commitsha??
var Version = semver.MustParse("3.4.141-74.DEROHE.STARGATE+26022022")
var Version = semver.MustParse("3.4.141-78.DEROHE.STARGATE+26022022")
6 changes: 3 additions & 3 deletions dvm/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *Simulator) SCInstall(sc_code string, incoming_values map[crypto.Hash]ui
entrypoint = "InitializePrivate"
}

gascompute, gasstorage, err = s.common(w_sc_tree, w_sc_data_tree, scid, s.height, s.height, uint64(time.Now().UnixMilli()), blid, scid, sc, entrypoint, 1, 0, signer_addr, incoming_values, SCDATA, fees, true)
gascompute, gasstorage, err = s.common(w_sc_tree, w_sc_data_tree, scid, s.height, s.height, uint64(time.Now().Unix()), blid, scid, sc, entrypoint, 1, 0, signer_addr, incoming_values, SCDATA, fees, true)
return
}

Expand Down Expand Up @@ -152,7 +152,7 @@ func (s *Simulator) RunSC(incoming_values map[crypto.Hash]uint64, SCDATA rpc.Arg
entrypoint := SCDATA.Value("entrypoint", rpc.DataString).(string)
balance, sc, _ := ReadSC(w_sc_tree, w_sc_data_tree, scid)

gascompute, gasstorage, err = s.common(w_sc_tree, w_sc_data_tree, scid, s.height, s.height, uint64(time.Now().UnixMilli()), blid, scid, sc, entrypoint, 1, balance, signer_addr, incoming_values, SCDATA, fees, true)
gascompute, gasstorage, err = s.common(w_sc_tree, w_sc_data_tree, scid, s.height, s.height, uint64(time.Now().Unix()), blid, scid, sc, entrypoint, 1, balance, signer_addr, incoming_values, SCDATA, fees, true)
return
default:
err = fmt.Errorf("unknown action_code code %d", action_code)
Expand All @@ -168,7 +168,7 @@ func (s *Simulator) common(w_sc_tree, w_sc_data_tree *Tree_Wrapper, scid crypto.
copy(signer[:], signer_addr.Compressed())
}

gascompute, gasstorage, err = Execute_sc_function(w_sc_tree, w_sc_data_tree, scid, bl_height, bl_topoheight, uint64(time.Now().UnixMilli()), blid, scid, sc, entrypoint, 1, 0, signer, incoming_values, SCDATA, fees, simulator)
gascompute, gasstorage, err = Execute_sc_function(w_sc_tree, w_sc_data_tree, scid, bl_height, bl_topoheight, uint64(time.Now().Unix()), blid, scid, sc, entrypoint, 1, 0, signer, incoming_values, SCDATA, fees, simulator)
fmt.Printf("sc execution error %s\n", err)

// we must commit all the changes
Expand Down
1 change: 1 addition & 0 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import "github.com/deroproject/derohe/rpc"

var Subsystem_Active uint32 // atomic counter to show how many subsystems are active
var Exit_In_Progress bool
var StartTime = time.Now()

// on init this variable is updated to setup global config in 1 go
var Config config.CHAIN_CONFIG = config.Mainnet // default is mainnnet
Expand Down
10 changes: 5 additions & 5 deletions p2p/chain_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ try_again:
// we should NOT queue blocks, instead we sent our chain request again
goto try_again

} else if chain.Get_Height()-response.Common.Height != 0 && chain.Get_Height()-response.Start_height <= config.STABLE_LIMIT {
pop_count = chain.Load_TOPO_HEIGHT() - response.Start_topoheight
} else if chain.Get_Height() < connection.Height && chain.Get_Height()-response.Start_height > config.STABLE_LIMIT { // we must somehow notify that deviation is way too much and manual interaction is necessary, so as any bug for chain deviationmay be detected
//connection.logger.V(1).Error(nil, "we have or others have deviated too much.you may have to use --sync-node option", "our topoheight", chain.Load_TOPO_HEIGHT(), "peer topoheight start", response.Start_topoheight)
//return
} else if chain.Get_Height()-response.Common.Height >= 0 && chain.Get_Height()-response.Start_height <= config.STABLE_LIMIT {
pop_count = chain.Load_TOPO_HEIGHT() - response.Start_topoheight
} else if chain.Get_Height()-response.Start_height > config.STABLE_LIMIT { // we must somehow notify that deviation is way too much and manual interaction is necessary, so as any bug for chain deviationmay be detected
connection.logger.V(1).Error(nil, "we have or others have deviated too much.you may have to use --sync-node option", "our topoheight", chain.Load_TOPO_HEIGHT(), "peer topoheight start", response.Start_topoheight)
return
//pop_count = chain.Load_TOPO_HEIGHT() - response.Start_topoheight
}

if pop_count >= 1 { // peer is claiming his chain is good and we should rewind
Expand Down
7 changes: 6 additions & 1 deletion p2p/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ func P2P_engine() {

// do not create connections to peers , if requested
if _, ok := globals.Arguments["--add-exclusive-node"]; ok && len(globals.Arguments["--add-exclusive-node"].([]string)) == 0 { // check if parameter is supported
go maintain_connection_to_peers() // maintain certain number of connections for peer to peers
go maintain_connection_to_peers() // maintain certain number of connections for peer to peers

// skip any connections, to allow more testing in closed environments
if os.Getenv("SKIP_SEED_NODES") != "" {
return
}
go maintain_seed_node_connection() // maintain connection with atleast 1 seed node

// this code only triggers when we do not have peer list
Expand Down
Loading

0 comments on commit db7eba4

Please sign in to comment.