Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
znn committed Apr 14, 2022
1 parent b2e6a98 commit c0f931d
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 121 deletions.
2 changes: 1 addition & 1 deletion common/types/spork.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

var (
AcceleratorSpork = NewImplementedSpork("97f0a9636a5cc633dfa3814e431f19c1974536eef3d1ebb713db50464dc5e750")
AcceleratorSpork = NewImplementedSpork("6d2b1e6cb4025f2f45533f0fe22e9b7ce2014d91cc960471045fa64eee5a6ba3")
ImplementedSporksMap = map[Hash]bool{
AcceleratorSpork.SporkId: true,
}
Expand Down
2 changes: 1 addition & 1 deletion metadata/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package metadata

const (
Version = "v0.0.3"
Version = "v0.0.4"
)
2 changes: 1 addition & 1 deletion metadata/version_libznn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package metadata

const (
Version = "v0.0.3-libznn"
Version = "v0.0.4-libznn"
)
2 changes: 1 addition & 1 deletion node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Config struct {

Name string

LogLevel string // "debug", "dbug" | "info" | "warn" | "error", "eror" | "crit"
LogLevel string // "debug", "dbug" | "info" | "warn" | "error", "error" | "crit"

Producer *ProducerConfig
RPC RPCConfig
Expand Down
190 changes: 99 additions & 91 deletions p2p/config.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vm/embedded/definition/plasma.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (entry *FusionInfo) Delete(context db.DB) error {
}

func getFusionInfoKey(addr types.Address, hash types.Hash) []byte {
return common.JoinBytes(tokenInfoKeyPrefix, addr.Bytes(), hash.Bytes())
return common.JoinBytes(fusionInfoKeyPrefix, addr.Bytes(), hash.Bytes())
}
func isFusionInfoKey(key []byte) bool {
return key[0] == fusionInfoKeyPrefix[0]
Expand Down
8 changes: 0 additions & 8 deletions vm/embedded/embedded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ func TestDumpContractsABIMethods(t *testing.T) {

common.Expect(t, dump, `
[
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"AddPhase", "id":"c7e13ddc", "signature":"AddPhase(hash,string,string,string,uint256,uint256)"}
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"CreateProject", "id":"77c044b6", "signature":"CreateProject(string,string,string,uint256,uint256)"}
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"Donate", "id":"cb7f8b2a", "signature":"Donate()"}
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"Update", "id":"20093ea6", "signature":"Update()"}
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"UpdatePhase", "id":"c1d7d323", "signature":"UpdatePhase(hash,string,string,string,uint256,uint256)"}
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"VoteByName", "id":"5c6c1064", "signature":"VoteByName(hash,string,uint8)"}
{"address":"z1qxemdeddedxaccelerat0rxxxxxxxxxxp4tk22", "name":"VoteByProdAddress", "id":"90ed001c", "signature":"VoteByProdAddress(hash,uint8)"}
{"address":"z1qxemdeddedxlyquydytyxxxxxxxxxxxxflaaae", "name":"BurnZnn", "id":"096b75a4", "signature":"BurnZnn(uint256)"}
{"address":"z1qxemdeddedxlyquydytyxxxxxxxxxxxxflaaae", "name":"Donate", "id":"cb7f8b2a", "signature":"Donate()"}
{"address":"z1qxemdeddedxlyquydytyxxxxxxxxxxxxflaaae", "name":"Fund", "id":"912f3c3f", "signature":"Fund(uint256,uint256)"}
{"address":"z1qxemdeddedxlyquydytyxxxxxxxxxxxxflaaae", "name":"Update", "id":"20093ea6", "signature":"Update()"}
{"address":"z1qxemdeddedxplasmaxxxxxxxxxxxxxxxxsctrp", "name":"CancelFuse", "id":"f9ca9dc3", "signature":"CancelFuse(hash)"}
{"address":"z1qxemdeddedxplasmaxxxxxxxxxxxxxxxxsctrp", "name":"Fuse", "id":"5ac942e8", "signature":"Fuse(address)"}
Expand Down
15 changes: 9 additions & 6 deletions vm/embedded/implementation/accelerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func checkMetaDataStatic(param *definition.AcceleratorParam) error {
}

func checkReceivedFunds(context vm_context.AccountVmContext, project *definition.Project) bool {
znnFunds := project.ZnnFundsNeeded
qsrFunds := project.QsrFundsNeeded
znnFunds := new(big.Int).Set(project.ZnnFundsNeeded)
qsrFunds := new(big.Int).Set(project.QsrFundsNeeded)
for _, phaseId := range project.PhaseIds {
phase, err := definition.GetPhaseEntry(context.Storage(), phaseId)
if err != nil {
Expand Down Expand Up @@ -201,7 +201,7 @@ func (p *AddPhaseMethod) ReceiveBlock(context vm_context.AccountVmContext, sendB
err := definition.ABIAccelerator.UnpackMethod(param, p.MethodName, sendBlock.Data)
common.DealWithErr(err)

// Check project exists and block is send by owner
// Check project exists and block is sent by owner
project, err := definition.GetProjectEntry(context.Storage(), param.Id)
if err != nil {
return nil, constants.ErrDataNonExistent
Expand Down Expand Up @@ -317,14 +317,16 @@ func (p *UpdateEmbeddedAcceleratorMethod) ReceiveBlock(context vm_context.Accoun
}

blocks := make([]*nom.AccountBlock, 0)
znnBalance, err := context.GetBalance(types.ZnnTokenStandard)
balanceZnn, err := context.GetBalance(types.ZnnTokenStandard)
if err != nil {
return nil, err
}
qsrBalance, err := context.GetBalance(types.QsrTokenStandard)
znnBalance := new(big.Int).Set(balanceZnn)
balanceQsr, err := context.GetBalance(types.QsrTokenStandard)
if err != nil {
return nil, err
}
qsrBalance := new(big.Int).Set(balanceQsr)

sort.Slice(projectList, func(i, j int) bool {
var phaseITimestamp, phaseJTimestamp int64
Expand All @@ -345,7 +347,7 @@ func (p *UpdateEmbeddedAcceleratorMethod) ReceiveBlock(context vm_context.Accoun
for _, project := range projectList {
if project.Status == definition.VotingStatus {
// Check if project voting period has ended
if project.CreationTimestamp+constants.AcceleratorProjectVotingPeriod > frontierMomentum.Timestamp.Unix() {
if project.CreationTimestamp+constants.AcceleratorProjectVotingPeriod >= frontierMomentum.Timestamp.Unix() {
ok := checkAcceleratorVotes(context, project.Id, numPillars)
acceleratorLog.Debug("project passed voting period", "project-id", project.Id, "passed-votes", ok)
if ok {
Expand Down Expand Up @@ -485,6 +487,7 @@ func (p *UpdatePhaseMethod) ReceiveBlock(context vm_context.AccountVmContext, se
newPhase.QsrFundsNeeded = param.QsrFundsNeeded
newPhase.CreationTimestamp = frontierMomentum.Timestamp.Unix()
newPhase.Status = definition.VotingStatus
newPhase.ProjectId = project.Id
newPhase.Save(context.Storage())

project.PhaseIds[len(project.PhaseIds)-1] = newPhase.Id
Expand Down
6 changes: 3 additions & 3 deletions vm/embedded/implementation/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (p *FundMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBlock
if err != nil {
return nil, err
}
if znnBalance.Cmp(param.ZnnReward) > 0 && qsrBalance.Cmp(param.QsrReward) > 0 {
if znnBalance.Cmp(param.ZnnReward) != -1 && qsrBalance.Cmp(param.QsrReward) != -1 {
znnReward := &nom.AccountBlock{
Address: types.LiquidityContract,
ToAddress: types.AcceleratorContract,
Expand All @@ -157,7 +157,7 @@ func (p *FundMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBlock
Amount: param.ZnnReward,
}
blocks = append(blocks, znnReward)
znnBalance = znnBalance.Sub(znnBalance, znnReward.Amount)

qsrReward := &nom.AccountBlock{
Address: types.LiquidityContract,
ToAddress: types.AcceleratorContract,
Expand Down Expand Up @@ -215,7 +215,7 @@ func (p *BurnZnnMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBl
if err != nil {
return nil, err
}
if znnBalance.Cmp(param.BurnAmount) > 0 {
if znnBalance.Cmp(param.BurnAmount) != -1 {
burnBlock := &nom.AccountBlock{
Address: types.LiquidityContract,
ToAddress: types.TokenContract,
Expand Down
2 changes: 1 addition & 1 deletion vm/embedded/implementation/pillars.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func checkAndRegisterPillar(context vm_context.AccountVmContext, param *definiti
// check if pillar name is used
_, err := definition.GetPillarInfo(context.Storage(), param.Name)
if err == constants.ErrDataNonExistent {
// ok, does not exists
// ok, does not exist
} else if err == nil {
return constants.ErrNotUnique
} else {
Expand Down
4 changes: 2 additions & 2 deletions vm/embedded/implementation/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ func (method *UpdateEmbeddedSentinelMethod) GetPlasma(plasmaTable *constants.Pla
func (method *UpdateEmbeddedSentinelMethod) ValidateSendBlock(block *nom.AccountBlock) error {
var err error

if err := definition.ABIStake.UnpackEmptyMethod(method.MethodName, block.Data); err != nil {
if err := definition.ABISentinel.UnpackEmptyMethod(method.MethodName, block.Data); err != nil {
return constants.ErrUnpackError
}

if block.Amount.Sign() != 0 {
return constants.ErrInvalidTokenOrAmount
}

block.Data, err = definition.ABIStake.PackMethod(method.MethodName)
block.Data, err = definition.ABISentinel.PackMethod(method.MethodName)
return err
}
func (method *UpdateEmbeddedSentinelMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBlock *nom.AccountBlock) ([]*nom.AccountBlock, error) {
Expand Down
7 changes: 6 additions & 1 deletion vm/embedded/implementation/spork.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *CreateSporkMethod) ValidateSendBlock(block *nom.AccountBlock) error {
}
func (p *CreateSporkMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBlock *nom.AccountBlock) ([]*nom.AccountBlock, error) {
if err := p.ValidateSendBlock(sendBlock); err != nil {
sentinelLog.Debug("invalid create - syntactic validation failed", "address", sendBlock.Address, "reason", err)
sporkLog.Debug("invalid create - syntactic validation failed", "address", sendBlock.Address, "reason", err)
return nil, err
}

Expand Down Expand Up @@ -110,6 +110,11 @@ func (p *ActivateSporkMethod) ValidateSendBlock(block *nom.AccountBlock) error {
return err
}
func (p *ActivateSporkMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBlock *nom.AccountBlock) ([]*nom.AccountBlock, error) {
if err := p.ValidateSendBlock(sendBlock); err != nil {
sporkLog.Debug("invalid spork activation - syntactic validation failed", "address", sendBlock.Address, "reason", err)
return nil, err
}

id := new(types.Hash)
err := definition.ABISpork.UnpackMethod(id, p.MethodName, sendBlock.Data)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions vm/embedded/implementation/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (p *IssueMethod) ReceiveBlock(context vm_context.AccountVmContext, sendBloc

tokenStandard := newTokenID(sendBlock.Hash)
if _, err := definition.GetTokenInfo(context.Storage(), tokenStandard); err == constants.ErrDataNonExistent {
} else if err != constants.ErrDataNonExistent {
common.DealWithErr(err)
} else if err == nil {
return nil, constants.ErrIDNotUnique
} else if err != constants.ErrDataNonExistent {
common.DealWithErr(err)
}

tokenInfo := definition.TokenInfo{
Expand Down
Loading

0 comments on commit c0f931d

Please sign in to comment.