diff --git a/block/miniblock.go b/block/miniblock.go index 275d97c4..dbe9e8d7 100644 --- a/block/miniblock.go +++ b/block/miniblock.go @@ -42,7 +42,7 @@ type MiniBlock struct { Final bool // bit 5 PastCount uint8 // previous count // bits 6,7 - Timestamp uint16 // can represent time from first block + Timestamp uint16 // represents rolling time Height uint64 // 5 bytes serialized in 5 bytes, Past [2]uint32 // 8 bytes used to build DAG of miniblocks and prevent number of attacks diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index c30b7b26..56a2b446 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -820,7 +820,7 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro } // we will directly use graviton to mov in to history - logger.V(3).Info("Full order data", "full_order", full_order, "base_topo_index", base_topo_index) + logger.V(1).Info("Full order data", "full_order", full_order, "base_topo_index", base_topo_index) if base_topo_index < 0 { logger.Error(nil, "negative base topo, not possible, probably disk corruption or core issue") @@ -880,7 +880,7 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro panic(err) } - logger.V(3).Info("reading block snapshot", "blid", full_order[i-1], "i", i, "record_version", record_version) + logger.V(1).Info("reading block snapshot", "blid", full_order[i-1], "i", i, "record_version", record_version) ss, err = chain.Store.Balance_store.LoadSnapshot(record_version) if err != nil { @@ -987,12 +987,12 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro chain.StoreBlock(bl_current, commit_version) topos_written = true chain.Store.Topo_store.Write(current_topo_block, full_order[i], commit_version, chain.Load_Block_Height(full_order[i])) - if logger.V(3).Enabled() { + if logger.V(1).Enabled() { merkle_root, err := chain.Load_Merkle_Hash(commit_version) if err != nil { panic(err) } - logger.V(3).Info("storing topo", "i", i, "blid", full_order[i].String(), "topoheight", current_topo_block, "commit_version", commit_version, "committed_merkle", merkle_root) + logger.V(1).Info("storing topo", "i", i, "blid", full_order[i].String(), "topoheight", current_topo_block, "commit_version", commit_version, "committed_merkle", merkle_root) } } @@ -1024,7 +1024,7 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro for i := range tips { tip_height := int64(chain.Load_Height_for_BL_ID(tips[i])) - if (chain_height - tip_height) < 2 { + if (chain_height - tip_height) == 0 { new_tips[tips[i]] = tips[i] } else { // this should be a rare event, unless network has very high latency diff --git a/blockchain/miner_block.go b/blockchain/miner_block.go index d2b53c4a..f750bced 100644 --- a/blockchain/miner_block.go +++ b/blockchain/miner_block.go @@ -352,12 +352,8 @@ func ConvertBlockToMiniblock(bl block.Block, miniblock_miner_address rpc.Address mbl.Height = bl.Height timestamp := uint64(globals.Time().UTC().UnixMilli()) - diff := timestamp - bl.Timestamp - mbl.Timestamp = 0xffff - if diff > 0xffff { - mbl.Timestamp = 0xffff - } - + mbl.Timestamp = uint16(timestamp) // this will help us better understand network conditions + mbl.PastCount = byte(len(bl.Tips)) for i := range bl.Tips { mbl.Past[i] = binary.BigEndian.Uint32(bl.Tips[i][:]) diff --git a/blockchain/sc.go b/blockchain/sc.go index 325584a3..8ff19806 100644 --- a/blockchain/sc.go +++ b/blockchain/sc.go @@ -158,8 +158,9 @@ func (chain *Blockchain) execute_sc_function(w_sc_tree *Tree_Wrapper, data_tree return } signer, err := extract_signer(&tx) - if err != nil { - return + if err != nil { // allow anonymous SC transactions with condition that SC will not call Signer + // this allows anonymous voting and numerous other applications + // otherwise SC receives signer as all zeroes } // setup block hash, height, topoheight correctly diff --git a/blockchain/transaction_execute.go b/blockchain/transaction_execute.go index 4d9ceb94..bfdf89bf 100644 --- a/blockchain/transaction_execute.go +++ b/blockchain/transaction_execute.go @@ -550,6 +550,7 @@ func (chain *Blockchain) process_transaction_sc(cache map[crypto.Hash]*graviton. func extract_signer(tx *transaction.Transaction) (signer [33]byte, err error) { for t := range tx.Payloads { if uint64(len(tx.Payloads[t].Statement.Publickeylist_compressed)) != tx.Payloads[t].Statement.RingSize { + panic("tx is not expanded") return signer, fmt.Errorf("tx is not expanded") } if tx.Payloads[t].SCID.IsZero() && tx.Payloads[t].Statement.RingSize == 2 { diff --git a/cmd/derod/main.go b/cmd/derod/main.go index c67e923d..dc1b8832 100644 --- a/cmd/derod/main.go +++ b/cmd/derod/main.go @@ -518,6 +518,44 @@ func readline_loop(l *readline.Instance, chain *blockchain.Blockchain, logger lo case command == "print_tree": // prints entire block chain tree //WriteBlockChainTree(chain, "/tmp/graph.dot") + case command == "install_block": + var hash crypto.Hash + + if len(line_parts) == 2 && len(line_parts[1]) == 64 { + bl_raw, err := hex.DecodeString(strings.ToLower(line_parts[1])) + if err != nil { + fmt.Printf("err while decoding blid err %s\n", err) + continue + } + copy(hash[:32], []byte(bl_raw)) + } else { + fmt.Printf("install_block needs a single block id as argument\n") + continue + } + + var bl block.Block + var cbl *block.Complete_Block + + if block_data, err := os.ReadFile(fmt.Sprintf("/tmp/blocks/%s", hash)); err == nil { + + if err = bl.Deserialize(block_data); err != nil { // we should deserialize the block here + logger.Error(err, "fError deserialiing block, block id %x len(data) %d data %x", hash[:], len(block_data), block_data, err) + continue + } + + cbl = &block.Complete_Block{Bl: &bl} + } else { + fmt.Printf("err reading block %s\n", err) + continue + } + + // bl, err := chain.Load_BL_FROM_ID(hash) + // if err != nil { + // fmt.Printf("Err %s\n", err) + // } + + err, _ = chain.Add_Complete_Block(cbl) + fmt.Printf("err adding block %s\n", err) case command == "print_block": @@ -661,7 +699,7 @@ func readline_loop(l *readline.Instance, chain *blockchain.Blockchain, logger lo if supply > (1000000 * 1000000000000) { supply -= (1000000 * 1000000000000) // remove premine } - fmt.Printf("Network %s Height %d NW Hashrate %0.03f MH/sec TH %s 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, chain.Get_Top_ID(), inc, out, mempool_tx_count, regpool_tx_count, globals.FormatMoney(supply)) + 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)) if chain.LocatePruneTopo() >= 1 { fmt.Printf("Chain is pruned till %d\n", chain.LocatePruneTopo()) } else { @@ -670,6 +708,14 @@ func readline_loop(l *readline.Instance, chain *blockchain.Blockchain, logger lo 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())) + 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") // print hardfork status on second line hf_state, _, _, threshold, version, votes, window := chain.Get_HF_info() diff --git a/config/config.go b/config/config.go index a4299521..ed99b686 100644 --- a/config/config.go +++ b/config/config.go @@ -103,7 +103,7 @@ var Mainnet = CHAIN_CONFIG{Name: "mainnet", } var Testnet = CHAIN_CONFIG{Name: "testnet", // testnet will always have last 3 bytes 0 - Network_ID: uuid.FromBytesOrNil([]byte{0x59, 0xd7, 0xf7, 0xe9, 0xdd, 0x48, 0xd5, 0xfd, 0x13, 0x0a, 0xf6, 0xe0, 0x72, 0x00, 0x00, 0x00}), + Network_ID: uuid.FromBytesOrNil([]byte{0x59, 0xd7, 0xf7, 0xe9, 0xdd, 0x48, 0xd5, 0xfd, 0x13, 0x0a, 0xf6, 0xe0, 0x73, 0x00, 0x00, 0x00}), P2P_Default_Port: 40401, RPC_Default_Port: 40402, Wallet_RPC_Default_Port: 40403, diff --git a/config/version.go b/config/version.go index 47a3bc5c..252f6ef0 100644 --- a/config/version.go +++ b/config/version.go @@ -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.91-1.DEROHE.STARGATE+25112021") +var Version = semver.MustParse("3.4.92-1.DEROHE.STARGATE+25112021") diff --git a/p2p/connection_pool.go b/p2p/connection_pool.go index 565c7a66..d7811c2f 100644 --- a/p2p/connection_pool.go +++ b/p2p/connection_pool.go @@ -56,34 +56,35 @@ const MAX_CLOCK_DATA_SET = 16 // This structure is used to do book keeping for the connection and keeps other DATA related to peer // golang restricts 64 bit uint64/int atomic on a 64 bit boundary -// therefore all atomics are on the top +// therefore all atomics are on the top, As suggested by Slixe type Connection struct { + Height int64 // last height sent by peer ( first member alignments issues) + StableHeight int64 // last stable height + TopoHeight int64 // topo height, current topo height, this is the only thing we require for syncing + Pruned int64 // till where chain has been pruned on this node + LastObjectRequestTime int64 // when was the last item placed in object list + Latency int64 // time.Duration // latency to this node when sending timed sync + BytesIn uint64 // total bytes in + BytesOut uint64 // total bytes out + Top_Version uint64 // current hard fork version supported by peer + Peer_ID uint64 // Remote peer id + Port uint32 // port advertised by other end as its server,if it's 0 server cannot accept connections + State uint32 // state of the connection + Client *rpc2.Client Conn net.Conn // actual object to talk ConnTls net.Conn // tls layered conn - Height int64 // last height sent by peer ( first member alignments issues) - StableHeight int64 // last stable height - TopoHeight int64 // topo height, current topo height, this is the only thing we require for syncing - StateHash crypto.Hash // statehash at the top - Pruned int64 // till where chain has been pruned on this node + StateHash crypto.Hash // statehash at the top - Created time.Time // when was object created - LastObjectRequestTime int64 // when was the last item placed in object list - BytesIn uint64 // total bytes in - BytesOut uint64 // total bytes out - Latency int64 // time.Duration // latency to this node when sending timed sync + Created time.Time // when was object created Incoming bool // is connection incoming or outgoing Addr net.Addr // endpoint on the other end - Port uint32 // port advertised by other end as its server,if it's 0 server cannot accept connections - Peer_ID uint64 // Remote peer id SyncNode bool // whether the peer has been added to command line as sync node - Top_Version uint64 // current hard fork version supported by peer ProtocolVersion string Tag string // tag for the other end DaemonVersion string - State uint32 // state of the connection Top_ID crypto.Hash // top block id of the connection logger logr.Logger // connection specific logger @@ -100,8 +101,7 @@ type Connection struct { clock_offsets [MAX_CLOCK_DATA_SET]time.Duration delays [MAX_CLOCK_DATA_SET]time.Duration clock_offset int64 // duration updated on every miniblock - - onceexit sync.Once + onceexit sync.Once Mutex sync.Mutex // used only by connection go routine }