Skip to content

Commit

Permalink
DERO HE Stargate Release 17
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDero committed Nov 9, 2021
1 parent cf3173c commit 9ef0d71
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 57 deletions.
2 changes: 1 addition & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (chain *Blockchain) Add_Complete_Block(cbl *block.Complete_Block) (err erro
for _, mbl := range bl.MiniBlocks {
var miner_hash crypto.Hash
copy(miner_hash[:], mbl.KeyHash[:])
if !chain.IsAddressHashValid(miner_hash) {
if !chain.IsAddressHashValid(true, miner_hash) {
err = fmt.Errorf("miner address not registered")
return err, false
}
Expand Down
32 changes: 17 additions & 15 deletions blockchain/miner_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,12 @@ func (chain *Blockchain) Create_new_block_template_mining(miniblock_miner_addres

var miner_hash crypto.Hash
copy(miner_hash[:], mbl.KeyHash[:])
if !chain.IsAddressHashValid(miner_hash) {
if !chain.IsAddressHashValid(false, miner_hash) {
logger.V(3).Error(err, "unregistered miner %s", miner_hash)
err = fmt.Errorf("unregistered miner or you need to wait 15 mins")
return
}

miniblock_blob = fmt.Sprintf("%x", mbl.Serialize())

return
Expand Down Expand Up @@ -527,14 +527,6 @@ func (chain *Blockchain) Accept_new_block(tstamp uint64, miniblock_blob []byte)
return
}

var miner_hash crypto.Hash
copy(miner_hash[:], mbl.KeyHash[:])
if !chain.IsAddressHashValid(miner_hash) {
logger.V(3).Error(err, "unregistered miner %s", miner_hash)
err = fmt.Errorf("unregistered miner or you need to wait 15 mins")
return
}

//fmt.Printf("received miniblock %x block %x\n", miniblock_blob, bl.Serialize())

// lets try to check pow to detect whether the miner is cheating
Expand All @@ -544,6 +536,14 @@ func (chain *Blockchain) Accept_new_block(tstamp uint64, miniblock_blob []byte)
return
}

var miner_hash crypto.Hash
copy(miner_hash[:], mbl.KeyHash[:])
if !chain.IsAddressHashValid(true, miner_hash) {
logger.V(3).Error(err, "unregistered miner %s", miner_hash)
err = fmt.Errorf("unregistered miner or you need to wait 15 mins")
return
}

// if we reach here, everything looks ok
bl.MiniBlocks = append(bl.MiniBlocks, mbl)

Expand Down Expand Up @@ -675,14 +675,16 @@ func (chain *Blockchain) ExpandMiniBlockTip(hash crypto.Hash) (result crypto.Has
}

// it is USED by consensus and p2p whether the miners has is valid
func (chain *Blockchain) IsAddressHashValid(hashes ...crypto.Hash) (found bool) {
func (chain *Blockchain) IsAddressHashValid(skip_cache bool, hashes ...crypto.Hash) (found bool) {

for _, hash := range hashes { // check whether everything could be satisfied via cache
if _, found := chain.cache_IsAddressHashValid.Get(fmt.Sprintf("%s", hash)); found {
goto hard_way // do things the hard way
if skip_cache {
for _, hash := range hashes { // check whether everything could be satisfied via cache
if _, found := chain.cache_IsAddressHashValid.Get(fmt.Sprintf("%s", hash)); !found {
goto hard_way // do things the hard way
}
}
return true
}
return true

hard_way:
// the block may just have been mined, so we evaluate roughly 25 past blocks to cross check
Expand Down
2 changes: 1 addition & 1 deletion blockchain/miniblocks_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (chain *Blockchain) InsertMiniBlock(mbl block.MiniBlock) (err error, result

var miner_hash crypto.Hash
copy(miner_hash[:], mbl.KeyHash[:])
if !chain.IsAddressHashValid(miner_hash) {
if !chain.IsAddressHashValid(true, miner_hash) {
logger.V(1).Error(err, "Invalid miner address")
err = fmt.Errorf("Invalid miner address")
return err, false
Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ const MAX_RINGSIZE = 128 // <= 128, ringsize will be accepted
// Minimum FEE calculation constants are here
const FEE_PER_KB = uint64(100) // .00100 dero per kb

const MAINNET_BOOTSTRAP_DIFFICULTY = uint64(800) // atlantis mainnet botstrapped at 200 MH/s
const MAINNET_MINIMUM_DIFFICULTY = uint64(800) // 800 H/s
const MAINNET_BOOTSTRAP_DIFFICULTY = uint64(80000000) // atlantis mainnet botstrapped at 80 MH/s
const MAINNET_MINIMUM_DIFFICULTY = uint64(800000000) // 80 MH/s

// testnet bootstraps at 1 MH
const TESTNET_BOOTSTRAP_DIFFICULTY = uint64(10000) // testnet bootstrap at 100 H/s
const TESTNET_MINIMUM_DIFFICULTY = uint64(10000) // 100 H/s
const TESTNET_BOOTSTRAP_DIFFICULTY = uint64(50000) // testnet bootstrap at 50KH/s
const TESTNET_MINIMUM_DIFFICULTY = uint64(10000) // 10KH/s

// this single parameter controls lots of various parameters
// within the consensus, it should never go below 7
Expand Down Expand Up @@ -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, 0x40, 0x00, 0x00, 0x00}),
Network_ID: uuid.FromBytesOrNil([]byte{0x59, 0xd7, 0xf7, 0xe9, 0xdd, 0x48, 0xd5, 0xfd, 0x13, 0x0a, 0xf6, 0xe0, 0x44, 0x00, 0x00, 0x00}),
P2P_Default_Port: 40401,
RPC_Default_Port: 40402,
Wallet_RPC_Default_Port: 40403,
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.4.38-1.DEROHE.STARGATE+08112021")
var Version = semver.MustParse("3.4.45-1.DEROHE.STARGATE+08112021")
40 changes: 40 additions & 0 deletions dvm/dvm_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,46 @@ var execution_tests_functions = []struct {
nil,
Variable{Type: String, ValueString: string(decodeHex("41FB"))},
},
{
"substr()",
`Function TestRun(input String) String
30 return substr(input,0,5)
End Function`,
"TestRun",
map[string]interface{}{"input": string("0123456789")},
nil,
Variable{Type: String, ValueString: string("01234")},
},
{
"substr()",
`Function TestRun(input String) String
30 return substr(input,1,5)
End Function`,
"TestRun",
map[string]interface{}{"input": string("0123456789")},
nil,
Variable{Type: String, ValueString: string("12345")},
},
{
"substr()",
`Function TestRun(input String) String
30 return substr(input,1,129)
End Function`,
"TestRun",
map[string]interface{}{"input": string("0123456789")},
nil,
Variable{Type: String, ValueString: string("123456789")},
},
{
"substr()",
`Function TestRun(input String) String
30 return substr(input,13,129)
End Function`,
"TestRun",
map[string]interface{}{"input": string("0123456789")},
nil,
Variable{Type: String, ValueString: string("")},
},
}

func decodeHex(s string) []byte {
Expand Down
2 changes: 2 additions & 0 deletions p2p/chain_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ func (connection *Connection) process_object_response(response Objects, sent int
processing_complete <- true
}()

defer globals.Recover(2)

for i := 0; i < len(response.CBlocks); i++ { // process incoming full blocks
var cbl block.Complete_Block // parse incoming block and deserialize it
var bl block.Block
Expand Down
51 changes: 27 additions & 24 deletions p2p/chunk_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,36 @@ func (connection *Connection) feed_chunk(chunk *Block_Chunk, sent int64) error {

var bl block.Block

if err := bl.Deserialize(chunk.BLOCK); err != nil {
logger.V(1).Error(err, "error deserializing block")
return nil
}
if bl.GetHash() != chunk.BLID {
return fmt.Errorf("Corrupted Chunk. bad block data")
}
var chunks *Chunks_Per_Block_Data
if chunksi, ok := chunk_map.Load(chunk.HHash); ok {
chunks = chunksi.(*Chunks_Per_Block_Data)
} else {

// we must check the Pow now
if int64(bl.Height) >= chain.Get_Height()-3 && int64(bl.Height) <= chain.Get_Height()+3 {
if err := bl.Deserialize(chunk.BLOCK); err != nil {
logger.V(1).Error(err, "error deserializing block")
return nil
}
if bl.GetHash() != chunk.BLID {
return fmt.Errorf("Corrupted Chunk. bad block data")
}

} else {
return nil // we need not broadcast
}
// we must check the Pow now
if int64(bl.Height) >= chain.Get_Height()-3 && int64(bl.Height) <= chain.Get_Height()+3 {

if len(bl.Tips) == 0 || len(bl.MiniBlocks) < 5 {
return nil
}
} else {
return nil // we need not broadcast
}

for _, mbl := range bl.MiniBlocks {
if !chain.VerifyMiniblockPoW(&bl, mbl) {
return errormsg.ErrInvalidPoW
if len(bl.Tips) == 0 || len(bl.MiniBlocks) < 5 {
return nil
}
}

broadcast_Chunk(chunk, 0, sent) // broadcast chunk INV
for _, mbl := range bl.MiniBlocks {
if !chain.VerifyMiniblockPoW(&bl, mbl) {
return errormsg.ErrInvalidPoW
}
}

var chunks *Chunks_Per_Block_Data
if chunksi, ok := chunk_map.Load(chunk.HHash); ok {
chunks = chunksi.(*Chunks_Per_Block_Data)
} else {
chunks = new(Chunks_Per_Block_Data)
chunks.Created = time.Now()
chunk_map.Store(chunk.HHash, chunks)
Expand All @@ -144,6 +143,10 @@ func (connection *Connection) feed_chunk(chunk *Block_Chunk, sent int64) error {
return nil
}

if chunks.Chunks[chunk.CHUNK_ID] == nil {
broadcast_Chunk(chunk, 0, sent) // broadcast chunk INV
}

chunks.Lock()
defer chunks.Unlock()

Expand Down
17 changes: 10 additions & 7 deletions p2p/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,6 @@ func (connection *Connection) isConnectionSyncing() (count int) {
func trigger_sync() {
defer globals.Recover(3)

topoheight := chain.Load_Block_Topological_order(chain.Get_Top_ID())

unique_map := UniqueConnections()

var clist []*Connection
Expand All @@ -822,12 +820,14 @@ func trigger_sync() {

for _, connection := range clist {

height := chain.Get_Height()

//connection.Lock() recursive mutex are not suported
// only choose highest available peers for syncing
if atomic.LoadUint32(&connection.State) != HANDSHAKE_PENDING && topoheight <= atomic.LoadInt64(&connection.TopoHeight) { // skip pre-handshake connections
if atomic.LoadUint32(&connection.State) != HANDSHAKE_PENDING && height < atomic.LoadInt64(&connection.Height) { // skip pre-handshake connections
// check whether we are lagging with this connection
//connection.Lock()
islagging := topoheight < atomic.LoadInt64(&connection.TopoHeight)
islagging := height < atomic.LoadInt64(&connection.Height)

//fmt.Printf("checking cdiff is lagging %+v topoheight %d peer topoheight %d \n", islagging, topoheight, connection.TopoHeight)

Expand All @@ -840,15 +840,18 @@ func trigger_sync() {
continue
}

if connection.Height >= (chain.Get_Height() + 1) { // give ourselves one sec, maybe the block is just being written
if connection.Height > chain.Get_Height() { // give ourselves one sec, maybe the block is just being written
time.Sleep(time.Second)
islagging = topoheight < atomic.LoadInt64(&connection.TopoHeight) // we only use topoheight, since pruned chain might not have full cdiff
height := chain.Get_Height()
islagging = height < atomic.LoadInt64(&connection.Height) // we only use topoheight, since pruned chain might not have full cdiff
} else {
continue
}

if islagging {
//connection.Lock()

connection.logger.V(1).Info("We need to resync with the peer", "height", connection.Height, "pruned", connection.Pruned)
connection.logger.V(1).Info("We need to resync with the peer", "our_height", height, "height", connection.Height, "pruned", connection.Pruned)

//connection.Unlock()
// set mode to syncronising
Expand Down
2 changes: 1 addition & 1 deletion p2p/rpc_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (c *Connection) NotifyMiniBlock(request Objects, response *Dummy) (err erro

var miner_hash crypto.Hash
copy(miner_hash[:], mbl.KeyHash[:])
if !chain.IsAddressHashValid(miner_hash) {
if !chain.IsAddressHashValid(false, miner_hash) { // this will use cache
c.logger.V(3).Error(err, "unregistered miner")
return fmt.Errorf("unregistered miner")
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/deroproject/graviton/node_leaf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/deroproject/graviton/special.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ef0d71

Please sign in to comment.