Skip to content

Commit

Permalink
Implements benchmarking and corrects timing of Yangon upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Jul 13, 2024
1 parent 790988c commit 100b858
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion env.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"guadalajara": 8,
"jinan": 9,
"alexandria": 9,
"yangon": 100,
"yangon": 10,
"washington": 10
}
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ func main() {
port := flag.String("port", "8080", "Port to listen on (server only)")
command := flag.String("command", "exit", "Run a command and exit")
Verbose = flag.Bool("verbose", false, "Set to true to enable verbose logging")
benchmark := flag.Bool("benchmark", false, "Set to true to enable benchmarking")
flag.Parse()
LoadEnv()
LoadStateCmd(nil)
SyncBlockchain(-1)
if len(Blockchain) == 0 {
Append(GenesisBlock())
}
if *benchmark {
Benchmark()
return
}
if *mine {
*serve = true
}
Expand Down
40 changes: 40 additions & 0 deletions node_util/benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package node_util

import (
"fmt"
"time"
)

func Benchmark() {
// Create transactions
for i := 0; i < 2; i++ {
transaction := Transaction{
Sender: PublicKey{
Y: GetKey("").PublicKey.Y,
},
Recipient: PublicKey{
Y: GetKey("").PublicKey.Y,
},
Amount: 0,
SenderSignature: Signature{},
Timestamp: time.Now(),
Contracts: nil,
Body: nil,
BodySignatures: nil,
FromSmartContract: false,
}
MiningTransactions = append(MiningTransactions, transaction)
}
// Start timer
start := time.Now()
// Create a block
block, err := CreateBlock()
if err != nil {
panic(err)
}
// Stop timer
elapsed := time.Since(start)
score := float64(block.Difficulty) / elapsed.Seconds()
fmt.Printf("Time: %s\n", elapsed)
fmt.Printf("Score: %f\n", score)
}
3 changes: 2 additions & 1 deletion node_util/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func GetDifficulty(lastTime time.Duration, lastDifficulty uint64) uint64 {
// Where x is the previous time times the previous difficulty, and 1 mdpm is 1000000 (1 million) difficulty points per minute.
difficultyBeforeAdjustment := lastDifficulty * uint64(60) / uint64(lastTime.Seconds())
x := lastTime.Minutes() * float64(lastDifficulty)
adjustment := (1 / (1 + math.Pow(math.E, -(1/Mdpm)*(x-Mdpm)))) + 0.5
var adjustment float64
adjustment = (1 / (1 + math.Pow(math.E, -(1/(10*Kdpm))*(x-Mdpm)))) + 0.5
difficultyAfterAdjustment := float64(difficultyBeforeAdjustment) / adjustment
difficultyUint64 := uint64(difficultyAfterAdjustment)
if difficultyUint64 > MinimumBlockDifficulty {
Expand Down

0 comments on commit 100b858

Please sign in to comment.