Skip to content

Commit 5be5777

Browse files
committed
DERO-HE STARGATE Testnet Release42
1 parent fb76ca9 commit 5be5777

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2500
-716
lines changed

blockchain/blockchain.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ func Blockchain_Start(params map[string]interface{}) (*Blockchain, error) {
277277
func (chain *Blockchain) IntegratorAddress() rpc.Address {
278278
return chain.integrator_address
279279
}
280+
func (chain *Blockchain) SetIntegratorAddress(addr rpc.Address) {
281+
chain.integrator_address = addr
282+
}
280283

281284
// this function is called to read blockchain state from DB
282285
// It is callable at any point in time
@@ -615,6 +618,11 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro
615618
block_logger.Error(fmt.Errorf("Double Registration TX"), "duplicate registration", "txid", cbl.Txs[i].GetHash())
616619
return errormsg.ErrTXDoubleSpend, false
617620
}
621+
622+
tx_hash := cbl.Txs[i].GetHash()
623+
if chain.simulator == false && tx_hash[0] != 0 && tx_hash[1] != 0 {
624+
return fmt.Errorf("Registration TX has not solved PoW"), false
625+
}
618626
reg_map[string(cbl.Txs[i].MinerAddress[:])] = true
619627
}
620628
}
@@ -1112,6 +1120,12 @@ func (chain *Blockchain) Add_TX_To_Pool(tx *transaction.Transaction) error {
11121120
return fmt.Errorf("premine tx not mineable")
11131121
}
11141122
if tx.IsRegistration() { // registration tx will not go any forward
1123+
1124+
tx_hash := tx.GetHash()
1125+
if chain.simulator == false && tx_hash[0] != 0 && tx_hash[1] != 0 {
1126+
return fmt.Errorf("TX doesn't solve Pow")
1127+
}
1128+
11151129
// ggive regpool a chance to register
11161130
if ss, err := chain.Store.Balance_store.LoadSnapshot(0); err == nil {
11171131
if balance_tree, err := ss.GetTree(config.BALANCE_TREE); err == nil {

blockchain/difficulty.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,19 @@ type DiffProvider interface {
191191

192192
func Get_Difficulty_At_Tips(source DiffProvider, tips []crypto.Hash) *big.Int {
193193
var MinimumDifficulty *big.Int
194+
GenesisDifficulty := new(big.Int).SetUint64(1)
194195

195196
if globals.IsMainnet() {
196197
MinimumDifficulty = new(big.Int).SetUint64(config.Settings.MAINNET_MINIMUM_DIFFICULTY) // this must be controllable parameter
198+
GenesisDifficulty = new(big.Int).SetUint64(config.Settings.MAINNET_BOOTSTRAP_DIFFICULTY)
197199
} else {
198200
MinimumDifficulty = new(big.Int).SetUint64(config.Settings.TESTNET_MINIMUM_DIFFICULTY) // this must be controllable parameter
201+
GenesisDifficulty = new(big.Int).SetUint64(config.Settings.TESTNET_BOOTSTRAP_DIFFICULTY)
199202
}
200-
GenesisDifficulty := new(big.Int).SetUint64(1)
201203

202204
if chain, ok := source.(*Blockchain); ok {
203205
if chain.simulator == true {
204-
return GenesisDifficulty
206+
return new(big.Int).SetUint64(1)
205207
}
206208
}
207209

@@ -225,7 +227,7 @@ func Get_Difficulty_At_Tips(source DiffProvider, tips []crypto.Hash) *big.Int {
225227

226228
// until we have atleast 2 blocks, we cannot run the algo
227229
if height < 3 {
228-
return MinimumDifficulty
230+
return GenesisDifficulty
229231
}
230232

231233
tip_difficulty := source.Load_Block_Difficulty(tips[0])

blockchain/hardcoded_contracts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ func (chain *Blockchain) install_hardcoded_contracts(cache map[crypto.Hash]*grav
5858

5959
if _, _, err = dvm.ParseSmartContract(source_nameservice); err != nil {
6060
logger.Error(err, "error Parsing hard coded sc")
61+
panic(err)
6162
return
6263
}
6364

6465
var name crypto.Hash
6566
name[31] = 1
6667
if err = chain.install_hardcoded_sc(cache, ss, balance_tree, sc_tree, source_nameservice, name); err != nil {
68+
panic(err)
6769
return
6870
}
6971

blockchain/storefs.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ type storefs struct {
3030
basedir string
3131
}
3232

33+
// TODO we need to enable big support or shift to object store at some point in time
34+
func (s *storefs) getpath(h [32]byte) string {
35+
// if you wish to use 3 level indirection, it will cause 16 million inodes to be used, but system will be faster
36+
//return filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
37+
// currently we are settling on 65536 inodes
38+
return filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]))
39+
}
40+
3341
// the filename stores the following information
3442
// hex block id (64 chars).block._ rewards (decimal) _ difficulty _ cumulative difficulty
3543

@@ -40,7 +48,7 @@ func (s *storefs) ReadBlock(h [32]byte) ([]byte, error) {
4048
return nil, fmt.Errorf("empty block")
4149
}
4250

43-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
51+
dir := s.getpath(h)
4452

4553
files, err := os.ReadDir(dir)
4654
if err != nil {
@@ -51,7 +59,7 @@ func (s *storefs) ReadBlock(h [32]byte) ([]byte, error) {
5159
for _, file := range files {
5260
if strings.HasPrefix(file.Name(), filename_start) {
5361
//fmt.Printf("Reading block with filename %s\n", file.Name())
54-
file := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]), file.Name())
62+
file := filepath.Join(dir, file.Name())
5563
return os.ReadFile(file)
5664
}
5765
}
@@ -61,7 +69,7 @@ func (s *storefs) ReadBlock(h [32]byte) ([]byte, error) {
6169

6270
// on windows, we see an odd behaviour where some files could not be deleted, since they may exist only in cache
6371
func (s *storefs) DeleteBlock(h [32]byte) error {
64-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
72+
dir := s.getpath(h)
6573

6674
files, err := os.ReadDir(dir)
6775
if err != nil {
@@ -72,7 +80,7 @@ func (s *storefs) DeleteBlock(h [32]byte) error {
7280
var found bool
7381
for _, file := range files {
7482
if strings.HasPrefix(file.Name(), filename_start) {
75-
file := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]), file.Name())
83+
file := filepath.Join(dir, file.Name())
7684
err = os.Remove(file)
7785
if err != nil {
7886
//return err
@@ -88,7 +96,7 @@ func (s *storefs) DeleteBlock(h [32]byte) error {
8896
}
8997

9098
func (s *storefs) ReadBlockDifficulty(h [32]byte) (*big.Int, error) {
91-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
99+
dir := s.getpath(h)
92100

93101
files, err := os.ReadDir(dir)
94102
if err != nil {
@@ -122,7 +130,7 @@ func (chain *Blockchain) ReadBlockSnapshotVersion(h [32]byte) (uint64, error) {
122130
return chain.Store.Block_tx_store.ReadBlockSnapshotVersion(h)
123131
}
124132
func (s *storefs) ReadBlockSnapshotVersion(h [32]byte) (uint64, error) {
125-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
133+
dir := s.getpath(h)
126134

127135
files, err := os.ReadDir(dir) // this always returns the sorted list
128136
if err != nil {
@@ -167,7 +175,7 @@ func (chain *Blockchain) ReadBlockHeight(h [32]byte) (uint64, error) {
167175
}
168176

169177
func (s *storefs) ReadBlockHeight(h [32]byte) (uint64, error) {
170-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
178+
dir := s.getpath(h)
171179

172180
files, err := os.ReadDir(dir)
173181
if err != nil {
@@ -194,7 +202,7 @@ func (s *storefs) ReadBlockHeight(h [32]byte) (uint64, error) {
194202
}
195203

196204
func (s *storefs) WriteBlock(h [32]byte, data []byte, difficulty *big.Int, ss_version uint64, height uint64) (err error) {
197-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
205+
dir := s.getpath(h)
198206
file := filepath.Join(dir, fmt.Sprintf("%x.block_%s_%d_%d", h[:], difficulty.String(), ss_version, height))
199207
if err = os.MkdirAll(dir, 0700); err != nil {
200208
return err
@@ -203,12 +211,13 @@ func (s *storefs) WriteBlock(h [32]byte, data []byte, difficulty *big.Int, ss_ve
203211
}
204212

205213
func (s *storefs) ReadTX(h [32]byte) ([]byte, error) {
206-
file := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]), fmt.Sprintf("%x.tx", h[:]))
214+
dir := s.getpath(h)
215+
file := filepath.Join(dir, fmt.Sprintf("%x.tx", h[:]))
207216
return ioutil.ReadFile(file)
208217
}
209218

210219
func (s *storefs) WriteTX(h [32]byte, data []byte) (err error) {
211-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
220+
dir := s.getpath(h)
212221
file := filepath.Join(dir, fmt.Sprintf("%x.tx", h[:]))
213222

214223
if err = os.MkdirAll(dir, 0700); err != nil {
@@ -219,7 +228,7 @@ func (s *storefs) WriteTX(h [32]byte, data []byte) (err error) {
219228
}
220229

221230
func (s *storefs) DeleteTX(h [32]byte) (err error) {
222-
dir := filepath.Join(filepath.Join(s.basedir, "bltx_store"), fmt.Sprintf("%02x", h[0]), fmt.Sprintf("%02x", h[1]), fmt.Sprintf("%02x", h[2]))
231+
dir := s.getpath(h)
223232
file := filepath.Join(dir, fmt.Sprintf("%x.tx", h[:]))
224233
return os.Remove(file)
225234
}

blockchain/transaction_execute.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,15 @@ func (chain *Blockchain) process_miner_transaction(bl *block.Block, genesis bool
7070

7171
if genesis == true { // process premine ,register genesis block, dev key
7272
balance := crypto.ConstructElGamal(acckey.G1(), crypto.ElGamal_BASE_G) // init zero balance
73-
balance = balance.Plus(new(big.Int).SetUint64(tx.Value << 1)) // add premine to users balance homomorphically
73+
balance = balance.Plus(new(big.Int).SetUint64(tx.Value)) // add premine to users balance homomorphically
7474
nb := crypto.NonceBalance{NonceHeight: 0, Balance: balance}
7575
balance_tree.Put(tx.MinerAddress[:], nb.Serialize()) // reserialize and store
7676

77+
if globals.IsMainnet() {
78+
return
79+
}
80+
81+
// only testnet/simulator will have dummy accounts to test
7782
// we must process premine list and register and give them balance,
7883
premine_count := 0
7984
scanner := bufio.NewScanner(strings.NewReader(premine.List))
@@ -119,21 +124,24 @@ func (chain *Blockchain) process_miner_transaction(bl *block.Block, genesis bool
119124
base_reward := CalcBlockReward(uint64(height))
120125
full_reward := base_reward + fees
121126

122-
//full_reward is divided into equal parts for all miner blocks + miner address
127+
integrator_reward := full_reward * 167 / 10000
128+
129+
//full_reward is divided into equal parts for all miner blocks
130+
// integrator only gets 1.67 % of block reward
123131
// since perfect division is not possible, ( see money handling)
124132
// any left over change is delivered to main miner who integrated the full block
125133

126-
share := full_reward / uint64(len(bl.MiniBlocks)) // one block integrator, this is integer division
127-
leftover := full_reward - (share * uint64(len(bl.MiniBlocks))) // only integrator will get this
134+
share := (full_reward - integrator_reward) / uint64(len(bl.MiniBlocks)) // one block integrator, this is integer division
135+
leftover := full_reward - integrator_reward - (share * uint64(len(bl.MiniBlocks))) // only integrator will get this
128136

129137
{ // giver integrator his reward
130138
balance_serialized, err := balance_tree.Get(tx.MinerAddress[:])
131139
if err != nil {
132140
panic(err)
133141
}
134142
nb := new(crypto.NonceBalance).Deserialize(balance_serialized)
135-
nb.Balance = nb.Balance.Plus(new(big.Int).SetUint64(share + leftover)) // add miners reward to miners balance homomorphically
136-
balance_tree.Put(tx.MinerAddress[:], nb.Serialize()) // reserialize and store
143+
nb.Balance = nb.Balance.Plus(new(big.Int).SetUint64(integrator_reward + leftover)) // add miners reward to miners balance homomorphically
144+
balance_tree.Put(tx.MinerAddress[:], nb.Serialize()) // reserialize and store
137145
}
138146

139147
// all the other miniblocks will get their share
@@ -230,7 +238,6 @@ func (chain *Blockchain) process_transaction(changed map[crypto.Hash]*graviton.T
230238
nb.NonceHeight = height
231239
}
232240
tree.Put(key_compressed, nb.Serialize()) // reserialize and store
233-
234241
}
235242
}
236243

cmd/dero-wallet-cli/easymenu_post_open.go

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
package main
1818

1919
import "io"
20-
20+
import "os"
2121
import "time"
2222
import "fmt"
23+
import "errors"
2324

24-
//import "io/ioutil"
2525
import "strings"
2626

27-
//import "path/filepath"
28-
//import "encoding/hex"
27+
import "path/filepath"
28+
import "encoding/json"
2929

3030
import "github.com/chzyer/readline"
3131

@@ -64,6 +64,7 @@ func display_easymenu_post_open_command(l *readline.Instance) {
6464
io.WriteString(w, "\t\033[1m12\033[0m\tTransfer all balance (send DERO) To Another Wallet\n")
6565
io.WriteString(w, "\t\033[1m13\033[0m\tShow transaction history\n")
6666
io.WriteString(w, "\t\033[1m14\033[0m\tRescan transaction history\n")
67+
io.WriteString(w, "\t\033[1m15\033[0m\tExport all transaction history in json format\n")
6768
}
6869

6970
io.WriteString(w, "\n\t\033[1m9\033[0m\tExit menu and start prompt\n")
@@ -127,10 +128,21 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
127128

128129
fmt.Fprintf(l.Stderr(), "Wallet address : "+color_green+"%s"+color_white+" is going to be registered.This is a pre-condition for using the online chain.It will take few seconds to register.\n", wallet.GetAddress())
129130

130-
reg_tx := wallet.GetRegistrationTX()
131-
132131
// at this point we must send the registration transaction
133132
fmt.Fprintf(l.Stderr(), "Wallet address : "+color_green+"%s"+color_white+" is going to be registered.Pls wait till the account is registered.\n", wallet.GetAddress())
133+
134+
fmt.Fprintf(l.Stderr(), "This will take a couple of minutes.Please wait....\n")
135+
136+
var reg_tx *transaction.Transaction
137+
for {
138+
139+
reg_tx = wallet.GetRegistrationTX()
140+
hash := reg_tx.GetHash()
141+
142+
if hash[0] == 0 && hash[1] == 0 {
143+
break
144+
}
145+
}
134146
fmt.Fprintf(l.Stderr(), "Registration TXID %s\n", reg_tx.GetHash())
135147
err := wallet.SendTransaction(reg_tx)
136148
if err != nil {
@@ -243,6 +255,7 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
243255

244256
if a.Arguments.Has(rpc.RPC_COMMENT, rpc.DataString) { // but only it is present
245257
logger.Info("Integrated Message", "comment", a.Arguments.Value(rpc.RPC_COMMENT, rpc.DataString))
258+
arguments = append(arguments, rpc.Argument{rpc.RPC_COMMENT, rpc.DataString, a.Arguments.Value(rpc.RPC_COMMENT, rpc.DataString)})
246259
}
247260
}
248261

@@ -291,10 +304,12 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
291304
amount_to_transfer = a.Arguments.Value(rpc.RPC_VALUE_TRANSFER, rpc.DataUint64).(uint64)
292305
} else {
293306

294-
amount_str := read_line_with_prompt(l, fmt.Sprintf("Enter amount to transfer in DERO (max TODO): "))
307+
mbal, _ := wallet.Get_Balance()
308+
amount_str := read_line_with_prompt(l, fmt.Sprintf("Enter amount to transfer in DERO (current balance %s): ", globals.FormatMoney(mbal)))
295309

296310
if amount_str == "" {
297-
amount_str = ".00001"
311+
logger.Error(nil, "Cannot transfer 0")
312+
break // invalid amount provided, bail out
298313
}
299314
amount_to_transfer, err = globals.ParseAmount(amount_str)
300315
if err != nil {
@@ -315,8 +330,15 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
315330

316331
// if no arguments, use space by embedding a small comment
317332
if len(arguments) == 0 { // allow user to enter Comment
333+
if v, err := ReadUint64(l, "Please enter payment id (or destination port number)", uint64(0)); err == nil {
334+
arguments = append(arguments, rpc.Argument{Name: rpc.RPC_DESTINATION_PORT, DataType: rpc.DataUint64, Value: v})
335+
} else {
336+
logger.Error(err, fmt.Sprintf("%s could not be parsed (type %s),", "Number", rpc.DataUint64))
337+
return
338+
}
339+
318340
if v, err := ReadString(l, "Comment", ""); err == nil {
319-
arguments = append(arguments, rpc.Argument{Name: "Comment", DataType: rpc.DataString, Value: v})
341+
arguments = append(arguments, rpc.Argument{Name: rpc.RPC_COMMENT, DataType: rpc.DataString, Value: v})
320342
} else {
321343
logger.Error(fmt.Errorf("%s could not be parsed (type %s),", "Comment", rpc.DataString), "")
322344
return
@@ -429,6 +451,34 @@ func handle_easymenu_post_open_command(l *readline.Instance, line string) (proce
429451
case "14":
430452
logger.Info("Rescanning wallet history")
431453
rescan_bc(wallet)
454+
case "15":
455+
if !ValidateCurrentPassword(l, wallet) {
456+
logger.Error(fmt.Errorf("Invalid password"), "")
457+
break
458+
}
459+
460+
if _, err := os.Stat("./history"); errors.Is(err, os.ErrNotExist) {
461+
if err := os.Mkdir("./history", 0700); err != nil {
462+
logger.Error(err, "Error creating directory")
463+
break
464+
}
465+
}
466+
467+
var zeroscid crypto.Hash
468+
account := wallet.GetAccount()
469+
for k, v := range account.EntriesNative {
470+
filename := filepath.Join("./history", k.String()+".json")
471+
if k == zeroscid {
472+
filename = filepath.Join("./history", "dero.json")
473+
}
474+
if data, err := json.Marshal(v); err != nil {
475+
logger.Error(err, "Error exporting data")
476+
} else if err = os.WriteFile(filename, data, 0600); err != nil {
477+
logger.Error(err, "Error exporting data")
478+
} else {
479+
logger.Info("successfully exported history", "file", filename)
480+
}
481+
}
432482

433483
default:
434484
processed = false // just loop

cmd/dero-wallet-cli/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Usage:
8080
--rpc-server Run rpc server, so wallet is accessible using api
8181
--rpc-bind=<127.0.0.1:20209> Wallet binds on this ip address and port
8282
--rpc-login=<username:password> RPC server will grant access based on these credentials
83+
--allow-rpc-password-change RPC server will change password if you send "Pass" header with new password
8384
`
8485
var menu_mode bool = true // default display menu mode
8586
//var account_valid bool = false // if an account has been opened, do not allow to create new account in this session
@@ -119,7 +120,7 @@ func main() {
119120
}
120121

121122
// init the lookup table one, anyone importing walletapi should init this first, this will take around 1 sec on any recent system
122-
walletapi.Initialize_LookupTable(1, 1<<17)
123+
walletapi.Initialize_LookupTable(1, 1<<21)
123124

124125
// We need to initialize readline first, so it changes stderr to ansi processor on windows
125126
l, err := readline.NewEx(&readline.Config{

0 commit comments

Comments
 (0)