From 90e1c89e1225b78fdac503bcd2bc66677a45eab3 Mon Sep 17 00:00:00 2001 From: Captain Date: Wed, 10 Nov 2021 16:33:19 +0000 Subject: [PATCH] DERO HE Stargate Release 20 --- blockchain/block_verify.go | 2 +- blockchain/blockchain.go | 23 +++++++++++- blockchain/miner_block.go | 12 ++++++ blockchain/transaction_verify.go | 4 +- cmd/derod/rpc/rpc_dero_getsc.go | 50 ++++++++++++++----------- cmd/explorer/explorerlib/explorerlib.go | 2 +- config/config.go | 2 +- config/version.go | 2 +- globals/globals.go | 4 +- p2p/chain_sync.go | 11 +++--- 10 files changed, 77 insertions(+), 35 deletions(-) diff --git a/blockchain/block_verify.go b/blockchain/block_verify.go index 9335819..c9ca4a3 100644 --- a/blockchain/block_verify.go +++ b/blockchain/block_verify.go @@ -46,7 +46,7 @@ func (b *cbl_verify) check(tx *transaction.Transaction, insert_for_future bool) b.data[p.SCID] = map[[33]byte]uint64{} } if p.Statement.RingSize != uint64(len(p.Statement.Publickeylist_compressed)) { - return fmt.Errorf("TX is not expanded. cannot cbl_verify") + return fmt.Errorf("TX is not expanded. cannot cbl_verify expected %d Actual %d", p.Statement.RingSize, len(p.Statement.Publickeylist_compressed)) } for j, pkc := range p.Statement.Publickeylist_compressed { diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 4a729b5..ffc4425 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -484,8 +484,15 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro if len(tx_checklist) != len(bl.Tx_hashes) { // block has duplicate tx, reject block_logger.Error(fmt.Errorf("duplicate TX"), "Incomplete block", "duplicate count", len(bl.Tx_hashes)-len(tx_checklist)) return errormsg.ErrInvalidBlock, false - } + + for i, tx := range cbl.Txs { + if tx.Height >= bl.Height { + block_logger.Error(fmt.Errorf("Invalid TX Height"), "TX height cannot be more than block", "txid", cbl.Txs[i].GetHash().String()) + return errormsg.ErrInvalidBlock, false + } + } + // now lets loop through complete block, matching each tx // detecting any duplicates using txid hash for i := 0; i < len(cbl.Txs); i++ { @@ -586,6 +593,20 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro var check_data cbl_verify // used to verify sanity of new block for i := 0; i < len(cbl.Txs); i++ { if !(cbl.Txs[i].IsCoinbase() || cbl.Txs[i].IsRegistration()) { // all other tx must go through this check + + for _, p := range cbl.Txs[i].Payloads { // make sure tx is expanded + if p.Statement.RingSize != uint64(len(p.Statement.Publickeylist_compressed)) { + if err = chain.Transaction_NonCoinbase_Expand(cbl.Txs[i]); err != nil { + return err, false + } + } + // if still the tx is not expanded, give err + if p.Statement.RingSize != uint64(len(p.Statement.Publickeylist_compressed)) { + err = fmt.Errorf("TXB is not expanded. cannot cbl_verify expected %d Actual %d", p.Statement.RingSize, len(p.Statement.Publickeylist_compressed)) + block_logger.Error(err, "Invalid TX within block", "txid", cbl.Txs[i].GetHash()) + return + } + } if err = check_data.check(cbl.Txs[i], false); err == nil { check_data.check(cbl.Txs[i], true) // keep in record for future tx } else { diff --git a/blockchain/miner_block.go b/blockchain/miner_block.go index 62bdf32..0fbc21b 100644 --- a/blockchain/miner_block.go +++ b/blockchain/miner_block.go @@ -217,6 +217,7 @@ func (chain *Blockchain) Create_new_miner_block(miner_address rpc.Address) (cbl // first of lets find the tx fees collected by consuming txs from mempool tx_hash_list_sorted := chain.Mempool.Mempool_List_TX_SortedInfo() // hash of all tx expected to be included within this block , sorted by fees + logger.V(8).Info("mempool returned tx list", "tx_list", tx_hash_list_sorted) var pre_check cbl_verify // used to verify sanity of new block i := 0 @@ -238,10 +239,21 @@ func (chain *Blockchain) Create_new_miner_block(miner_address rpc.Address) (cbl sizeoftxs += tx_hash_list_sorted[i].Size cbl.Txs = append(cbl.Txs, tx) tx_hash_list_included = append(tx_hash_list_included, tx_hash_list_sorted[i].Hash) + logger.V(8).Info("tx selecting for mining ", "txlist", tx_hash_list_sorted[i].Hash) + } else { + logger.V(8).Info("not selecting tx due to pre_check failure", "txid", tx_hash_list_sorted[i].Hash) } + } else { + logger.V(8).Info("not selecting tx due to nonce failure", "txid", tx_hash_list_sorted[i].Hash) } + } else { + logger.V(8).Info("not selecting tx due to height difference", "txid", tx_hash_list_sorted[i].Hash) } + } else { + logger.V(8).Info("not selecting tx due to height", "txid", tx_hash_list_sorted[i].Hash) } + } else { + logger.V(8).Info("not selecting tx since tx is nil", "txid", tx_hash_list_sorted[i].Hash) } } // any left over transactions, should be randomly selected diff --git a/blockchain/transaction_verify.go b/blockchain/transaction_verify.go index e7a8b27..e348355 100644 --- a/blockchain/transaction_verify.go +++ b/blockchain/transaction_verify.go @@ -413,12 +413,12 @@ func (chain *Blockchain) Verify_Transaction_NonCoinbase(hf_version int64, tx *tr return fmt.Errorf("mentioned balance tree not found, cannot verify TX") } - if _, ok := transaction_valid_cache.Load(tx_hash); ok { + /*if _, ok := transaction_valid_cache.Load(tx_hash); ok { logger.V(1).Info("Found in cache, skipping verification", "txid", tx_hash) return nil } else { //logger.Infof("TX not found in cache %s len %d ",tx_hash, len(tmp_buffer)) - } + }*/ //logger.Infof("dTX state tree has been found") diff --git a/cmd/derod/rpc/rpc_dero_getsc.go b/cmd/derod/rpc/rpc_dero_getsc.go index 8d2d53d..dd4645f 100644 --- a/cmd/derod/rpc/rpc_dero_getsc.go +++ b/cmd/derod/rpc/rpc_dero_getsc.go @@ -38,7 +38,7 @@ func GetSC(ctx context.Context, p rpc.GetSC_Params) (result rpc.GetSC_Result, er defer func() { // safety so if anything wrong happens, we return error if r := recover(); r != nil { - err = fmt.Errorf("panic occured. stack trace %s", debug.Stack()) + err = fmt.Errorf("panic occured. stack trace r %s %s", r, debug.Stack()) } }() @@ -101,29 +101,35 @@ func GetSC(ctx context.Context, p rpc.GetSC_Params) (result rpc.GetSC_Result, er for k, v, err = cursor.First(); err == nil; k, v, err = cursor.Next() { var vark, varv dvm.Variable - if nil == vark.UnmarshalBinary(k) && nil == varv.UnmarshalBinary(v) { - switch vark.Type { - case dvm.Uint64: - if varv.Type == dvm.Uint64 { - result.VariableUint64Keys[vark.ValueUint64] = varv.ValueUint64 - } else { - result.VariableUint64Keys[vark.ValueUint64] = fmt.Sprintf("%x", []byte(varv.ValueString)) + _ = vark + _ = varv + _ = k + _ = v + /* + fmt.Printf("key '%x' value '%x'\n", k,v) + if len(k) == 32 && len(v) == 8 { // it's SC balance + result.Balances[fmt.Sprintf("%x", k)] = binary.BigEndian.Uint64(v) + } else if nil == vark.UnmarshalBinary(k) && nil == varv.UnmarshalBinary(v) { + switch vark.Type { + case dvm.Uint64: + if varv.Type == dvm.Uint64 { + result.VariableUint64Keys[vark.ValueUint64] = varv.ValueUint64 + } else { + result.VariableUint64Keys[vark.ValueUint64] = fmt.Sprintf("%x", []byte(varv.ValueString)) + } + + case dvm.String: + if varv.Type == dvm.Uint64 { + result.VariableStringKeys[vark.ValueString] = varv.ValueUint64 + } else { + result.VariableStringKeys[vark.ValueString] = fmt.Sprintf("%x", []byte(varv.ValueString)) + } + default: + err = fmt.Errorf("UNKNOWN Data type") + return } - case dvm.String: - if varv.Type == dvm.Uint64 { - result.VariableStringKeys[vark.ValueString] = varv.ValueUint64 - } else { - result.VariableStringKeys[vark.ValueString] = fmt.Sprintf("%x", []byte(varv.ValueString)) - } - default: - err = fmt.Errorf("UNKNOWN Data type") - return - } - - } else if len(k) == 32 && len(v) == 8 { // it's SC balance - result.Balances[fmt.Sprintf("%x", k)] = binary.BigEndian.Uint64(v) - } + } */ } } diff --git a/cmd/explorer/explorerlib/explorerlib.go b/cmd/explorer/explorerlib/explorerlib.go index 47d2078..2c613c9 100644 --- a/cmd/explorer/explorerlib/explorerlib.go +++ b/cmd/explorer/explorerlib/explorerlib.go @@ -588,7 +588,7 @@ func load_tx_from_rpc(info *txinfo, txhash string) (err error) { var r rpc.GetSC_Result if err = rpc_client.Call("DERO.GetSC", p, &r); err != nil { - return fmt.Errorf("gettransa rpc failed err %s", err) + logger.V(1).Error(err, "DERO.GetSC failed") } else { info.SC_State = r } diff --git a/config/config.go b/config/config.go index 0569178..bc44d79 100644 --- a/config/config.go +++ b/config/config.go @@ -97,7 +97,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, 0x44, 0x00, 0x00, 0x00}), + Network_ID: uuid.FromBytesOrNil([]byte{0x59, 0xd7, 0xf7, 0xe9, 0xdd, 0x48, 0xd5, 0xfd, 0x13, 0x0a, 0xf6, 0xe0, 0x45, 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 a735233..852a234 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.49-1.DEROHE.STARGATE+09112021") +var Version = semver.MustParse("3.4.54-1.DEROHE.STARGATE+09112021") diff --git a/globals/globals.go b/globals/globals.go index 76fb493..e3d2297 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -211,10 +211,12 @@ func Initialize() { } // used to recover in case of panics -func Recover(level int) { +func Recover(level int) (err error) { if r := recover(); r != nil { + err = fmt.Errorf("Recovered r:%+v stack %s", r, fmt.Sprintf("%s", string(debug.Stack()))) Logger.V(level).Error(nil, "Recovered ", "error", r, "stack", fmt.Sprintf("%s", string(debug.Stack()))) } + return } // tells whether we are in mainnet mode diff --git a/p2p/chain_sync.go b/p2p/chain_sync.go index 766ef63..5a05c9b 100644 --- a/p2p/chain_sync.go +++ b/p2p/chain_sync.go @@ -97,9 +97,10 @@ try_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 - chain.Rewind_Chain(int(pop_count)) // pop as many blocks as necessary, assumming peer has given us good chain - } else { // we must somehow notify that deviation is way too much and manual interaction is necessary, so as any bug for chain deviationmay be detected + //pop_count := chain.Load_TOPO_HEIGHT() - response.Start_topoheight + //chain.Rewind_Chain(int(pop_count)) // pop as many blocks as necessary, assumming peer has given us good chain + } 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 } @@ -138,7 +139,7 @@ try_again: } // request alt-tips ( blocks if we are nearing the main tip ) - if (response.Common.TopoHeight - chain.Load_TOPO_HEIGHT()) <= 5 { + /*if (response.Common.TopoHeight - chain.Load_TOPO_HEIGHT()) <= 5 { for i := range response.TopBlocks { if chain.Load_Block_Topological_order(response.TopBlocks[i]) == -1 { //connection.Send_ObjectRequest([]crypto.Hash{response.TopBlocks[i]}, []crypto.Hash{}) @@ -147,7 +148,7 @@ try_again: } } - } + }*/ }