This commit is contained in:
server 2020-07-12 16:41:10 -04:00
parent f525063801
commit e9b11c1972
4 changed files with 2 additions and 24 deletions

View File

@ -1,5 +1,5 @@
.PHONY: default build
default: build
build: node.go client.go serve.go
build: node.go client.go serve.go values.go
go build -o node node.go serve.go values.go
go build -o client client.go values.go

View File

@ -242,7 +242,7 @@ func (chain *BlockChain) timeIsValid(block *Block, index uint64) bool {
}
result := btime.Sub(ltime)
return result >= TIME_SESSION
return result > 0
}
func (chain *BlockChain) hashIsValid(block *Block, index uint64) bool {

View File

@ -31,7 +31,6 @@ const (
GENESIS_REWARD = 100
DIFFICULTY = 20 // 15
TXS_LIMIT = 2 // 6
TIME_SESSION = 1 * time.Minute // minutes
START_PERCENT = 10
RAND_BYTES = 32
)

View File

@ -12,7 +12,6 @@ import (
"os"
"strconv"
"strings"
"time"
)
var (
@ -195,21 +194,8 @@ func addTransaction(pack *nt.Package) string {
return "fail"
}
if len(Block.Transactions) == bc.TXS_LIMIT {
lastBlock := getLastBlock()
if lastBlock == nil {
return "fail"
}
btime, err := time.Parse(time.RFC3339, lastBlock.TimeStamp)
if err != nil {
return "fail"
}
mod := time.Now().Sub(btime)
diff := mod < bc.TIME_SESSION
go func() {
block := *Block
if diff {
time.Sleep(bc.TIME_SESSION - mod)
}
IsMining = true
res := Chain.AcceptBlock(User, &block, BreakMining)
IsMining = false
@ -223,13 +209,6 @@ func addTransaction(pack *nt.Package) string {
return "ok"
}
func getLastBlock() *bc.Block {
var sblock string
row := Chain.DB.QueryRow("SELECT Block FROM BlockChain ORDER BY Id DESC")
row.Scan(&sblock)
return bc.DeserializeBlock(sblock)
}
func pushBlockToNet(block *bc.Block) {
var sblock = bc.SerializeBlock(block)
for _, addr := range Addresses {