From 03c6c16f6964a8373be80ea893cc930f4ba3c341 Mon Sep 17 00:00:00 2001 From: Captain Date: Sun, 28 Feb 2021 06:54:30 +0000 Subject: [PATCH] DERO-HE STARGATE Testnet Release14 --- config/version.go | 2 +- globals/globals.go | 4 ++-- walletapi/wallet_pool.go | 32 +++++++++++++++----------------- walletapi/wallet_transfer.go | 9 +++++---- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/config/version.go b/config/version.go index 4dc85c4..86af59b 100644 --- a/config/version.go +++ b/config/version.go @@ -20,4 +20,4 @@ import "github.com/blang/semver" // right now it has to be manually changed // do we need to include git commitsha?? -var Version = semver.MustParse("3.2.13-1.DEROHE.STARGATE+27022021") +var Version = semver.MustParse("3.2.14-1.DEROHE.STARGATE+28022021") diff --git a/globals/globals.go b/globals/globals.go index d4d9d42..db0dbec 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -127,8 +127,8 @@ func Initialize() { // used to recover in case of panics func Recover() { if r := recover(); r != nil { - rlog.Warnf("Recovered while handling connection, Stack trace below", r) - rlog.Warnf("Stack trace \n%s", debug.Stack()) + rlog.Warnf("Recovered, error %s", r) + rlog.Warnf("Stack trace \n%s\n", debug.Stack()) } } diff --git a/walletapi/wallet_pool.go b/walletapi/wallet_pool.go index b667e6f..e8b3e73 100644 --- a/walletapi/wallet_pool.go +++ b/walletapi/wallet_pool.go @@ -19,7 +19,6 @@ package walletapi // the objective of this file is to implememt a pool which sends and retries transactions until they are accepted by the chain import "fmt" -import "runtime/debug" //import "encoding/binary" //import "encoding/hex" @@ -36,7 +35,7 @@ import "github.com/deroproject/derohe/cryptography/crypto" //import "github.com/deroproject/derohe/crypto/ringct" //import "github.com/deroproject/derohe/transaction" -//import "github.com/deroproject/derohe/globals" +import "github.com/deroproject/derohe/globals" //import "github.com/deroproject/derohe/address" import "github.com/deroproject/derohe/rpc" @@ -187,12 +186,7 @@ func (w *Wallet_Memory) processPool(checkonly bool) error { return nil } - defer func() { - if r := recover(); r != nil { - rlog.Warnf("Stack trace \n%s", debug.Stack()) - - } - }() + defer globals.Recover() if !w.GetMode() { // if wallet is in offline mode , we cannot do anything return fmt.Errorf("wallet is in offline mode") @@ -226,8 +220,10 @@ func (w *Wallet_Memory) processPool(checkonly bool) error { } if tx_result.Txs_as_hex[0] == "" { - try.Status = "Lost (not in mempool/chain, Waiting for more" - if try.Height > info.StableHeight { // we have attempted, lets wait some blocks, this needs to be optimized, for instant transfer + try.Status = "Lost (not in mempool/chain), Waiting for more blocks to retry" + if try.Height < (info.StableHeight + 1) { // we have attempted, lets wait some blocks, this needs to be optimized, for instant transfer + // we need to send this tx again now + }else{ continue // try other txs } } else if tx_result.Txs[0].In_pool { @@ -237,15 +233,16 @@ func (w *Wallet_Memory) processPool(checkonly bool) error { try.Status = fmt.Sprintf("Mined in %s (%d confirmations)", tx_result.Txs[0].ValidBlock, info.TopoHeight-tx_result.Txs[0].Block_Height) if try.Height < (info.StableHeight + 1) { // successful confirmation w.account.PoolHistory = append(w.account.PoolHistory, w.account.Pool[i]) - rlog.Infof("tx %s confirmed successfully at stableheight %d height %d trigger_height %d\n", try.TXID.String(), info.StableHeight, try.Height, w.account.Pool[i].Trigger_Height) + rlog.Infof("tx %s confirmed successfully at stableheight %d height %d trigger_height %d\n", try.TXID.String(), info.StableHeight, try.Height, w.account.Pool[i].Trigger_Height) w.account.Pool = append(w.account.Pool[:i], w.account.Pool[i+1:]...) i-- // so another element at same place gets used - } continue } else { - try.Status = fmt.Sprintf("Mined in sideblock (%d confirmations, waiting for more)", info.Height-try.Height) - if try.Height < info.StableHeight { // we have attempted, lets wait some blocks, this needs to be optimized, for instant transfer + try.Status = fmt.Sprintf("Mined in sideblock (%d confirmations, waiting for more blocks)", info.Height-try.Height) + if try.Height < (info.StableHeight + 1) { // we have attempted, lets wait some blocks, this needs to be optimized, for instant transfer + // we need to send this tx again now + }else{ continue // try other txs } } @@ -256,20 +253,21 @@ func (w *Wallet_Memory) processPool(checkonly bool) error { // we are here means we have to dispatch tx first time or again or whatever the case rlog.Debugf("%d tries, sending\n", len(w.account.Pool[i].Tries)) + if len(w.account.Pool[i].Tries) >= 1 { + rlog.Debugf("tries status %+v\n", w.account.Pool[i].Tries) // for debug + } tx, err := w.TransferPayload0(w.account.Pool[i].Transfers, w.account.Pool[i].Transfer_Everything, w.account.Pool[i].SCDATA, false) - //tx, err := w.Transfer_Simplified(w.account.Pool[i].Addr, w.account.Pool[i].Amount, w.account.Pool[i].Data) if err != nil { rlog.Errorf("err building tx %s\n", err) return err } - + w.account.Pool[i].Tries = append(w.account.Pool[i].Tries, Try{int64(tx.Height), tx.GetHash(), "Dispatched to mempool"}) if err = w.SendTransaction(tx); err != nil { rlog.Errorf("err sending tx %s\n", err) return err } rlog.Infof("dispatched tx %s at height %d trigger_height %d\n", tx.GetHash().String(), tx.Height, w.account.Pool[i].Trigger_Height) - w.account.Pool[i].Tries = append(w.account.Pool[i].Tries, Try{int64(tx.Height), tx.GetHash(), "Dispatched to mempool"}) break // we can only send one tx per height } } diff --git a/walletapi/wallet_transfer.go b/walletapi/wallet_transfer.go index 514ea78..19a68b1 100644 --- a/walletapi/wallet_transfer.go +++ b/walletapi/wallet_transfer.go @@ -66,8 +66,6 @@ func (w *Wallet_Memory) TransferPayload0(transfers []rpc.Transfer, transfer_all defer w.transfer_mutex.Unlock() ringsize := uint64(w.account.Ringsize) // use wallet mixin, if mixin not provided - bits_needed := make([]int, ringsize, ringsize) - // if wallet is online,take the fees from the network itself // otherwise use whatever user has provided //if w.GetMode() { @@ -186,6 +184,9 @@ func (w *Wallet_Memory) TransferPayload0(transfers []rpc.Transfer, transfer_all ringsize = 2 // only for easier testing } + bits_needed := make([]int, ringsize, ringsize) + + bits_needed[0], self_e, err = w.GetEncryptedBalanceAtTopoHeight(transfers[t].SCID, -1, w.GetAddress().String()) if err != nil { fmt.Printf("self unregistered err %s\n", err) @@ -217,13 +218,13 @@ func (w *Wallet_Memory) TransferPayload0(transfers []rpc.Transfer, transfer_all }*/ receiver_without_payment_id := addr.BaseAddress() - for i, k := range w.random_ring_members(transfers[t].SCID) { + for _, k := range w.random_ring_members(transfers[t].SCID) { if len(ring_members_keys)+2 < int(ringsize) && k != receiver_without_payment_id.String() && k != w.GetAddress().String() { // fmt.Printf("%s receiver %s sender %s\n", k, receiver_without_payment_id.String(), w.GetAddress().String()) var ebal *crypto.ElGamal var addr *rpc.Address - bits_needed[i+2], ebal, err = w.GetEncryptedBalanceAtTopoHeight(transfers[t].SCID, -1, k) + bits_needed[len(ring_members_keys)], ebal, err = w.GetEncryptedBalanceAtTopoHeight(transfers[t].SCID, -1, k) if err != nil { fmt.Printf(" unregistered %s\n", k) return