Skip to content

Commit

Permalink
DERO-HE STARGATE Mainnet Release47
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDero committed Mar 3, 2022
1 parent c2113b6 commit fa50602
Show file tree
Hide file tree
Showing 27 changed files with 386 additions and 139 deletions.
1 change: 1 addition & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,7 @@ func (chain *Blockchain) get_ordered_past(tip crypto.Hash, tillheight int64) (or
// this will flip chain top, depending on which block has more work
// more worked block is normally identified in < 2 secs
func (chain *Blockchain) flip_top() {
return
chain.Lock()
defer chain.Unlock()

Expand Down
67 changes: 31 additions & 36 deletions blockchain/hardcoded_contracts.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2021 DERO Project. All rights reserved.
// Copyright 2017-2022 DERO Project. All rights reserved.
// Use of this source code in any form is governed by RESEARCH license.
// license can be found in the LICENSE file.
// GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
Expand All @@ -18,58 +18,53 @@ package blockchain

// this file installs hard coded contracts

//import "fmt"
import _ "embed"

/*
import "strings"
import "strconv"
import "encoding/hex"
import "encoding/binary"
import "math/big"
import "golang.org/x/xerrors"
import "github.com/deroproject/derohe/cryptography/bn256"
import "github.com/deroproject/derohe/transaction"
import "github.com/deroproject/derohe/config"
import "github.com/deroproject/derohe/premine"
import "github.com/deroproject/derohe/globals"
import "github.com/deroproject/derohe/block"
import "github.com/deroproject/derohe/rpc"
*/

import "github.com/deroproject/graviton"
import "github.com/deroproject/derohe/dvm"
import "github.com/deroproject/derohe/cryptography/crypto"

//go:embed hardcoded_sc/nameservice.bas
var source_nameservice string

//go:embed hardcoded_sc/nameservice_updateable.bas
var source_nameservice_updateable string

// process the miner tx, giving fees, miner rewatd etc
func (chain *Blockchain) install_hardcoded_contracts(cache map[crypto.Hash]*graviton.Tree, ss *graviton.Snapshot, balance_tree *graviton.Tree, sc_tree *graviton.Tree, height uint64) (err error) {

if height != 0 {
return
}
if height == 0 {

if _, _, err = dvm.ParseSmartContract(source_nameservice); err != nil {
logger.Error(err, "error Parsing hard coded sc")
panic(err)
return
}
if _, _, err = dvm.ParseSmartContract(source_nameservice); err != nil {
logger.Error(err, "error Parsing hard coded sc")
panic(err)
return
}

var name crypto.Hash
name[31] = 1
if err = chain.install_hardcoded_sc(cache, ss, balance_tree, sc_tree, source_nameservice, name); err != nil {
panic(err)
return
}

var name crypto.Hash
name[31] = 1
if err = chain.install_hardcoded_sc(cache, ss, balance_tree, sc_tree, source_nameservice, name); err != nil {
panic(err)
return
}

//fmt.Printf("source code embedded %s\n",source_nameservice)
if height == 21480 { // update SC at specific height
if _, _, err = dvm.ParseSmartContract(source_nameservice_updateable); err != nil {
logger.Error(err, "error Parsing hard coded sc")
panic(err)
return
}

var name crypto.Hash
name[31] = 1
if err = chain.install_hardcoded_sc(cache, ss, balance_tree, sc_tree, source_nameservice_updateable, name); err != nil {
panic(err)
return
}
}

return
}
Expand Down
54 changes: 54 additions & 0 deletions blockchain/hardcoded_sc/nameservice_updateable.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Name Service SMART CONTRACT in DVM-BASIC.
Allows a user to register names which could be looked by wallets for easy to use name while transfer
*/


// This function is used to initialize parameters during install time
Function Initialize() Uint64
10 RETURN 0
End Function

// Register a name, limit names of 5 or less length
Function Register(name String) Uint64
10 IF EXISTS(name) THEN GOTO 50 // if name is already used, it cannot reregistered
15 IF STRLEN(name) >= 64 THEN GOTO 50 // skip names misuse
20 IF STRLEN(name) >= 6 THEN GOTO 40
30 IF SIGNER() == address_raw("deto1qyvyeyzrcm2fzf6kyq7egkes2ufgny5xn77y6typhfx9s7w3mvyd5qqynr5hx") THEN GOTO 40
35 IF SIGNER() != address_raw("deto1qy0ehnqjpr0wxqnknyc66du2fsxyktppkr8m8e6jvplp954klfjz2qqdzcd8p") THEN GOTO 50
40 STORE(name,SIGNER())
50 RETURN 0
End Function


// This function is used to change owner of Name is an string form of address
Function TransferOwnership(name String,newowner String) Uint64
10 IF LOAD(name) != SIGNER() THEN GOTO 30
20 STORE(name,ADDRESS_RAW(newowner))
30 RETURN 0
End Function


// This function is used to change SC owner
Function TransferSCOwnership(newowner String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("own1",ADDRESS_RAW(newowner))
40 RETURN 0
End Function

// Until the new owner claims ownership, existing owner remains owner
Function ClaimSCOwnership() Uint64
10 IF LOAD("own1") == SIGNER() THEN GOTO 30
20 RETURN 1
30 STORE("owner",SIGNER()) // ownership claim successful
40 RETURN 0
End Function

// If signer is owner, provide him rights to update code anytime
// make sure update is always available to SC
Function UpdateCode(SC_CODE String) Uint64
10 IF LOAD("owner") == SIGNER() THEN GOTO 30
20 RETURN 1
30 UPDATE_SC_CODE(SC_CODE)
40 RETURN 0
End Function
Empty file.
2 changes: 1 addition & 1 deletion blockchain/hardfork_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var mainnet_hard_forks = []Hard_fork{
// {1, 0,0,0,0,true}, // dummy entry so as we can directly use the fork index into this entry
{1, 0, 0, 0, 0, true}, // version 1 hard fork where genesis block landed and chain migration occurs
// version 1 has difficulty hardcoded to 1
//{2, 95551, 0, 0, 0, true}, // version 2 hard fork where Atlantis bootstraps , it's mandatory
//{2, 10, 0, 0, 0, true}, // version 2 hard fork where SC gets update functionality , it's mandatory
// {3, 721000, 0, 0, 0, true}, // version 3 hard fork emission fix, it's mandatory
}

Expand Down
2 changes: 2 additions & 0 deletions blockchain/storetopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (s *storetopofs) Write(index int64, blid [32]byte, state_version uint64, he

_, err = s.topomapping.WriteAt(buf[:], index*TOPORECORD_SIZE)

s.topomapping.Sync() // looks like this is the cause of corruption

return err
}

Expand Down
2 changes: 1 addition & 1 deletion build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bash $ABSDIR/build_package.sh "./cmd/explorer"
bash $ABSDIR/build_package.sh "./cmd/dero-wallet-cli"
bash $ABSDIR/build_package.sh "./cmd/dero-miner"
#bash $ABSDIR/build_package.sh "./cmd/simulator"
bash $ABSDIR/build_package.sh "./cmd/rpc_examples/pong_server"
#bash $ABSDIR/build_package.sh "./cmd/rpc_examples/pong_server"


for d in build/*; do cp Start.md "$d"; done
Expand Down
2 changes: 0 additions & 2 deletions cmd/dero-wallet-cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ func usage(w io.Writer) {
io.WriteString(w, "\t\033[1mhelp\033[0m\t\tthis help\n")
io.WriteString(w, "\t\033[1maddress\033[0m\t\tDisplay user address\n")
io.WriteString(w, "\t\033[1mbalance\033[0m\t\tDisplay user balance\n")
io.WriteString(w, "\t\033[1mget_tx_key\033[0m\tDisplay tx proof to prove receiver for specific transaction\n")
io.WriteString(w, "\t\033[1mintegrated_address\033[0m\tDisplay random integrated address (with encrypted payment ID)\n")
io.WriteString(w, "\t\033[1mmenu\033[0m\t\tEnable menu mode\n")
io.WriteString(w, "\t\033[1mrescan_bc\033[0m\tRescan blockchain to re-obtain transaction history \n")
Expand All @@ -909,7 +908,6 @@ func usage(w io.Writer) {
io.WriteString(w, "\t\033[1mtransfer\033[0m\tTransfer/Send DERO to another address\n")
io.WriteString(w, "\t\t\tEg. transfer <address> <amount>\n")
io.WriteString(w, "\t\033[1mtransfer_all\033[0m\tTransfer everything to another address\n")
io.WriteString(w, "\t\033[1mflush\033[0m\tFlush local wallet pool (for testing purposes)\n")
io.WriteString(w, "\t\033[1mversion\033[0m\t\tShow version\n")
io.WriteString(w, "\t\033[1mbye\033[0m\t\tQuit wallet\n")
io.WriteString(w, "\t\033[1mexit\033[0m\t\tQuit wallet\n")
Expand Down
80 changes: 80 additions & 0 deletions cmd/derod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,42 @@ func main() {
p2p.Broadcast_MiniBlock(mbl, peerid)
}

{
current_blid, err := chain.Load_Block_Topological_order_at_index(17600)
if err == nil {

current_blid := current_blid
for {
height := chain.Load_Height_for_BL_ID(current_blid)

if height < 17500 {
break
}

r, err := chain.Store.Topo_store.Read(int64(height))
if err != nil {
panic(err)
}
if r.BLOCK_ID != current_blid {
fmt.Printf("Fixing corruption r %+v , current_blid %s current_blid_height %d\n", r, current_blid, height)

fix_commit_version, err := chain.ReadBlockSnapshotVersion(current_blid)
if err != nil {
panic(err)
}

chain.Store.Topo_store.Write(int64(height), current_blid, fix_commit_version, int64(height))

}

fix_bl, err := chain.Load_BL_FROM_ID(current_blid)
if err != nil {
panic(err)
}
current_blid = fix_bl.Tips[0]
}
}
}
globals.Cron.Start() // start cron jobs

// This tiny goroutine continuously updates status as required
Expand Down Expand Up @@ -624,6 +660,50 @@ restart_loop:
err, _ = chain.Add_Complete_Block(cbl)
fmt.Printf("err adding block %s\n", err)

case command == "fix":
tips := chain.Get_TIPS()

current_blid := tips[0]
for {
height := chain.Load_Height_for_BL_ID(current_blid)

//fmt.Printf("checking height %d\n", height)

if height < 1 {
break
}

r, err := chain.Store.Topo_store.Read(int64(height))
if err != nil {
panic(err)
}
if r.BLOCK_ID != current_blid {
fmt.Printf("corruption due to XYZ r %+v , current_blid %s current_blid_height\n", r, current_blid, height)

fix_commit_version, err := chain.ReadBlockSnapshotVersion(current_blid)
if err != nil {
panic(err)
}

chain.Store.Topo_store.Write(int64(height), current_blid, fix_commit_version, int64(height))

}

fix_bl, err := chain.Load_BL_FROM_ID(current_blid)
if err != nil {
panic(err)
}

current_blid = fix_bl.Tips[0]

/* fix_commit_version, err = chain.ReadBlockSnapshotVersion(current_block_id)
if err != nil {
panic(err)
}
*/

}

case command == "print_block":

fmt.Printf("printing block\n")
Expand Down
Loading

0 comments on commit fa50602

Please sign in to comment.