Skip to content

Commit

Permalink
Fixes: Wallet sync issues, certificate negative serial bug, bbolt dep…
Browse files Browse the repository at this point in the history
…endency.
  • Loading branch information
CaptainDero committed Oct 1, 2022
1 parent 50b376e commit 89a1e1e
Show file tree
Hide file tree
Showing 65 changed files with 323 additions and 72 deletions.
4 changes: 2 additions & 2 deletions build_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ for PLATFORM in $PLATFORMS; do
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}"
echo mkdir -p $OUTPUT_DIR
if [[ "${GOOS}" == "windows" ]]; then BIN_FILENAME="${BIN_FILENAME}.exe"; fi
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -gcflags=${GCFLAGS} -o $OUTPUT_DIR/${BIN_FILENAME} $package"
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -trimpath -ldflags=-buildid= -gcflags=${GCFLAGS} -o $OUTPUT_DIR/${BIN_FILENAME} $package"
echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"

Expand All @@ -75,7 +75,7 @@ for GOOS in $PLATFORMS_ARM; do
for GOARM in 7; do
OUTPUT_DIR="${ABSDIR}/build/dero_${GOOS}_${GOARCH}${GOARM}"
BIN_FILENAME="${OUTPUT}-${GOOS}-${GOARCH}${GOARM}"
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build -gcflags=${GCFLAGS} -o $OUTPUT_DIR/${BIN_FILENAME} $package"
CMD="GOARM=${GOARM} GOOS=${GOOS} GOARCH=${GOARCH} go build -trimpath -ldflags=-buildid= -gcflags=${GCFLAGS} -o $OUTPUT_DIR/${BIN_FILENAME} $package"
echo "${CMD}"
eval "${CMD}" || FAILURES="${FAILURES} ${GOOS}/${GOARCH}${GOARM}"
done
Expand Down
25 changes: 25 additions & 0 deletions cmd/dero-wallet-cli/easymenu_pre_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import "io"
import "fmt"
import "time"
import "strconv"
import "strings"
import "encoding/hex"

Expand Down Expand Up @@ -222,6 +223,30 @@ func common_processing(wallet *walletapi.Wallet_Disk) {
wallet.SetOnlineMode()
}

if globals.Arguments["--scan-top-n-blocks"] != nil && globals.Arguments["--scan-top-n-blocks"].(string) != "" {
s, err := strconv.ParseInt(globals.Arguments["--scan-top-n-blocks"].(string), 10, 64)
if err != nil {
logger.Error(err, "Error parsing number(in numeric form)")
} else {
wallet.SetTrackRecentBlocks(s)
if wallet.SetTrackRecentBlocks(-1) == 0 {
logger.Info("Wallet will track entire history")
} else {
logger.Info("Wallet will track recent blocks", "blocks", wallet.SetTrackRecentBlocks(-1))
}
}
}

if globals.Arguments["--save-every-x-seconds"] != nil && globals.Arguments["--save-every-x-seconds"].(string) != "" {
s, err := strconv.ParseUint(globals.Arguments["--save-every-x-seconds"].(string), 10, 64)
if err != nil {
logger.Error(err, "Error parsing seconds(in numeric form)")
} else {
wallet.SetSaveDuration(time.Duration(s) * time.Second)
logger.Info("Wallet changes will be saved every", "duration (seconds)", wallet.SetSaveDuration(-1))
}
}

wallet.SetNetwork(!globals.Arguments["--testnet"].(bool))

// start rpc server if requested
Expand Down
6 changes: 4 additions & 2 deletions cmd/dero-wallet-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ Usage:
--rpc-bind=<127.0.0.1:20209> Wallet binds on this ip address and port
--rpc-login=<username:password> RPC server will grant access based on these credentials
--allow-rpc-password-change RPC server will change password if you send "Pass" header with new password
--scan-top-n-blocks=<100000> Only scan top N blocks
--save-every-x-seconds=<300> Save wallet every x seconds
`
var menu_mode bool = true // default display menu mode
//var account_valid bool = false // if an account has been opened, do not allow to create new account in this session
// var account_valid bool = false // if an account has been opened, do not allow to create new account in this session
var offline_mode bool // whether we are in offline mode
var sync_in_progress int // whether sync is in progress with daemon
var wallet *walletapi.Wallet_Disk //= &walletapi.Account{} // all account data is available here
//var address string
// var address string
var sync_time time.Time // used to suitable update prompt

var default_offline_datafile string = "getoutputs.bin"
Expand Down
41 changes: 41 additions & 0 deletions cmd/dero-wallet-cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func handle_prompt_command(l *readline.Instance, line string) {
filename, err := ReadString(l, "Enter file to sign", "")
if err != nil {
logger.Error(err, "Cannot read input file name")
break
}

outputfile := filename + ".sign"
Expand All @@ -162,6 +163,7 @@ func handle_prompt_command(l *readline.Instance, line string) {
filename, err := ReadString(l, "Enter file to verify signature", "")
if err != nil {
logger.Error(err, "Cannot read input file name")
break
}

outputfile := strings.TrimSuffix(filename, ".sign")
Expand All @@ -184,6 +186,40 @@ func handle_prompt_command(l *readline.Instance, line string) {

}

case "filesign_huge": // sign a hugefile contents
if !ValidateCurrentPassword(l, wallet) {
logger.Error(err, "Invalid password")
PressAnyKey(l, wallet)
break
}

filename, err := ReadString(l, "Enter file to sign", "")
if err != nil {
logger.Error(err, "Cannot read input file name")
break
}

if err := wallet.SignFile(filename); err != nil {
logger.Error(err, "Cannot sign", "file", filename)
} else {
logger.Info("successfully signed file. please check", "file", filename, "signature", filename+".signed")
}

case "fileverify_huge": // verify a file contents
filename, err := ReadString(l, "Enter file to verify signature", "")
if err != nil {
logger.Error(err, "Cannot read input file name")
break
}

if signer, err := wallet.CheckFileSignature(filename); err != nil {
logger.Error(err, "Signature verify failed", "file", filename)
} else {
logger.Info("Signed by", "address", signer.String())

logger.Info("Signature verified successfully.", "file", filename)
}

case "password": // change wallet password
if ConfirmYesNoDefaultNo(l, "Change wallet password (y/N)") &&
ValidateCurrentPassword(l, wallet) {
Expand Down Expand Up @@ -435,6 +471,9 @@ func handle_set_command(l *readline.Instance, line string) {
fmt.Fprintf(l.Stderr(), color_extra_white+"Current settings"+color_extra_white+"\n")
fmt.Fprintf(l.Stderr(), color_normal+"Seed Language: "+color_extra_white+"%s\t"+color_normal+"eg. "+color_extra_white+"set seed language\n"+color_normal, wallet.GetSeedLanguage())
fmt.Fprintf(l.Stderr(), color_normal+"Ringsize: "+color_extra_white+"%d\t"+color_normal+"eg. "+color_extra_white+"set ringsize 16\n"+color_normal, wallet.GetRingSize())
fmt.Fprintf(l.Stderr(), color_normal+"Save Every : "+color_extra_white+"%s \t"+color_normal+"eg. "+color_extra_white+"default value:0 (set using command line)\n"+color_normal, wallet.SetSaveDuration(-1))
fmt.Fprintf(l.Stderr(), color_normal+"Track Recent Blocks : "+color_extra_white+"%d \t"+color_normal+"eg. "+color_extra_white+"default value:0 means track all blocks (set using command line)\n"+color_normal, wallet.SetTrackRecentBlocks(-1))

fmt.Fprintf(l.Stderr(), color_normal+"Priority: "+color_extra_white+"%0.2f\t"+color_normal+"eg. "+color_extra_white+"set priority 4.0\t"+color_normal+"Transaction priority on DERO network \n", wallet.GetFeeMultiplier())
fmt.Fprintf(l.Stderr(), "\t\tMinimum priority is 1.00. High priority = high fees\n")

Expand Down Expand Up @@ -867,6 +906,8 @@ var completer = readline.NewPrefixCompleter(
readline.PcItem("get_tx_key"),
readline.PcItem("filesign"),
readline.PcItem("fileverify"),
readline.PcItem("filesign_huge"),
readline.PcItem("fileverify_huge"),
readline.PcItem("menu"),
readline.PcItem("rescan_bc"),
readline.PcItem("payment_id"),
Expand Down
5 changes: 5 additions & 0 deletions cmd/derod/rpc/rpc_dero_gettxpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ func GetTxPool(ctx context.Context) (result rpc.GetTxPool_Result) {
for i := range pool_list {
result.Tx_list = append(result.Tx_list, fmt.Sprintf("%s", pool_list[i]))
}

reg_list := chain.Regpool.Regpool_List_TX()
for i := range reg_list {
result.Tx_list = append(result.Tx_list, fmt.Sprintf("%s", reg_list[i]))
}
return result
}
3 changes: 2 additions & 1 deletion cmd/derod/rpc/rpc_dero_sendrawtransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import "github.com/deroproject/derohe/rpc"
import "github.com/deroproject/derohe/p2p"
import "github.com/deroproject/derohe/transaction"

//NOTE: finally we have shifted to json api
// NOTE: finally we have shifted to json api
func SendRawTransaction(ctx context.Context, p rpc.SendRawTransaction_Params) (result rpc.SendRawTransaction_Result, err error) {

defer func() { // safety so if anything wrong happens, we return error
Expand Down Expand Up @@ -61,6 +61,7 @@ func SendRawTransaction(ctx context.Context, p rpc.SendRawTransaction_Params) (r
if err = chain.Add_TX_To_Pool(&tx); err == nil {
p2p.Broadcast_Tx(&tx, 0) // broadcast tx
result.Status = "OK"
result.TXID = fmt.Sprintf("%s", tx.GetHash())
} else {
err = fmt.Errorf("Transaction %s rejected by daemon err '%s'", tx.GetHash(), err)
}
Expand Down
29 changes: 18 additions & 11 deletions cmd/rpc_examples/pong_server/pong_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import "fmt"
import "time"
import "crypto/sha1"

import "etcd.io/bbolt"
import "go.etcd.io/bbolt"

import "github.com/go-logr/logr"
import "gopkg.in/natefinch/lumberjack.v2"
Expand All @@ -36,8 +36,8 @@ var expected_arguments = rpc.Arguments{
// { Name:rpc.RPC_EXPIRY , DataType:rpc.DataTime, Value:time.Now().Add(time.Hour).UTC()},
{Name: rpc.RPC_COMMENT, DataType: rpc.DataString, Value: "Purchase PONG"},
//{"float64", rpc.DataFloat64, float64(0.12345)}, // in atomic units
// {Name:rpc.RPC_NEEDS_REPLYBACK_ADDRESS,DataType:rpc.DataUint64,Value:uint64(0)}, // this service will reply to incoming request,so needs the senders address
{Name: rpc.RPC_VALUE_TRANSFER, DataType: rpc.DataUint64, Value: uint64(12345)}, // in atomic units
{Name: rpc.RPC_NEEDS_REPLYBACK_ADDRESS, DataType: rpc.DataUint64, Value: uint64(0)}, // this service will reply to incoming request,so needs the senders address
{Name: rpc.RPC_VALUE_TRANSFER, DataType: rpc.DataUint64, Value: uint64(12345)}, // in atomic units

}

Expand Down Expand Up @@ -167,16 +167,23 @@ func processing_thread(db *bbolt.DB) {
continue
}

/* if !e.Payload_RPC.Has(rpc.RPC_REPLYBACK_ADDRESS, rpc.DataAddress){
logger.Error(nil, fmt.Sprintf("user has not give his address so we cannot replyback")) // this is an unexpected situation
continue
}
if !e.Payload_RPC.Has(rpc.RPC_REPLYBACK_ADDRESS, rpc.DataAddress) {
logger.Error(nil, fmt.Sprintf("user has not give his address so we cannot replyback")) // this is an unexpected situation
continue
}

destination_expected := e.Payload_RPC.Value(rpc.RPC_REPLYBACK_ADDRESS, rpc.DataAddress).(rpc.Address).String()
addr, err := rpc.NewAddress(destination_expected)
if err != nil {
logger.Error(err, "err while while parsing incoming addr")
continue
}
addr.Mainnet = false // convert addresses to testnet form, by default it's expected to be mainnnet
destination_expected = addr.String()

destination_expected := e.Payload_RPC.Value(rpc.RPC_REPLYBACK_ADDRESS, rpc.DataAddress).(rpc.Address).String()
logger.V(1).Info("tx should be replied", "txid", e.TXID, "replyback_address", destination_expected)

logger.V(1).Info("tx should be replied", "txid", e.TXID,"replyback_address",destination_expected)
*/
destination_expected := e.Sender
//destination_expected := e.Sender

// value received is what we are expecting, so time for response
response[0].Value = e.SourcePort // source port now becomes destination port, similar to TCP
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.5.1-110a.DEROHE.STARGATE+26022022")
var Version = semver.MustParse("3.5.2-113.DEROHE.STARGATE+01102022")
8 changes: 7 additions & 1 deletion p2p/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func IsAddressConnected(address string) bool {
// add connection to map, only if we are not connected already
// we also check for limits for incoming connections
// same ip max 8 ip ( considering NAT)
//same Peer ID 4
// same Peer ID 4
func Connection_Add(c *Connection) bool {
if dup, ok := connection_map.LoadOrStore(Address(c), c); !ok {
c.Created = time.Now()
Expand Down Expand Up @@ -396,6 +396,7 @@ func broadcast_Block_Coded(cbl *block.Complete_Block, PeerID uint64, first_seen

our_height := chain.Get_Height()
// build the request once and dispatch it to all possible peers
tries := 0
count := 0
unique_map := UniqueConnections()

Expand Down Expand Up @@ -425,6 +426,11 @@ func broadcast_Block_Coded(cbl *block.Complete_Block, PeerID uint64, first_seen
return
default:
}

if tries > 1024 {
return
}
tries++
if atomic.LoadUint32(&v.State) != HANDSHAKE_PENDING && PeerID != v.Peer_ID && v.Peer_ID != GetPeerID() { // skip pre-handshake connections

// if the other end is > 2 blocks behind, do not broadcast block to him
Expand Down
2 changes: 1 addition & 1 deletion p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GetPeerID() uint64 {
if peerid == 0 {
var buf [8]byte
rand.Read(buf[:])
peerid = binary.LittleEndian.Uint64(buf[:])
peerid = binary.LittleEndian.Uint64(buf[:]) & 0x7FFFFFFFFFFFFFFF
}
return peerid
}
3 changes: 2 additions & 1 deletion rpc/daemon_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type (
}
)

//get encrypted balance call
// get encrypted balance call
type (
GetEncryptedBalance_Params struct {
Address string `json:"address"`
Expand Down Expand Up @@ -268,6 +268,7 @@ type (
}
SendRawTransaction_Result struct {
Status string `json:"status"`
TXID string `json:"txid"`
Reason string `json:"string"`
}
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 89a1e1e

Please sign in to comment.