Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gordon-sero committed Nov 15, 2018
1 parent 0359bd6 commit d3b181c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, local bool) (int, []interf
}

for _, tx := range block.Transactions() {
err := stx.Verify(tx.GetZZSTX())
err := stx.Verify(tx.GetZZSTX(), &state.GetZState().State0)
if err != nil {
return i, events, coalescedLogs, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrGasLimit
}

err := stx.Verify(tx.GetZZSTX())
err := stx.Verify(tx.GetZZSTX(), &pool.currentState.GetZState().State0)
if err != nil {
return ErrVerifyError
}
Expand Down
22 changes: 14 additions & 8 deletions zero/txs/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package txs
import (
"errors"

"github.com/sero-cash/go-sero/zero/txs/zstate"

"github.com/sero-cash/go-czero-import/cpt"

"github.com/sero-cash/go-czero-import/keys"
Expand Down Expand Up @@ -160,11 +162,10 @@ func CheckInt(i *utils.I256) bool {
return CheckUint(&abs)
}

func Verify(s *stx.T) (e error) {
st1 := state1.CurrentState1()
return Verify_state1(s, st1)
func Verify(s *stx.T, state *zstate.State0) (e error) {
return Verify_state1(s, state)
}
func Verify_state1(s *stx.T, state *state1.State1) (e error) {
func Verify_state1(s *stx.T, state *zstate.State0) (e error) {
balance_desc := cpt.BalanceDesc{}

hash_z := s.ToHash_for_o()
Expand Down Expand Up @@ -192,12 +193,12 @@ func Verify_state1(s *stx.T, state *state1.State1) (e error) {
}

for _, in_o := range s.Desc_O.Ins {
if ok := state.State0.HasIn(&in_o.Root); ok {
if ok := state.HasIn(&in_o.Root); ok {
e = errors.New("txs.verify in already in nils")
return
} else {
}
if src, err := state.State0.GetOut(&in_o.Root); e == nil {
if src, err := state.GetOut(&in_o.Root); e == nil {
if src.IsO() {
if keys.VerifyPKr(&hash_z, &in_o.Sign, &src.Out_O.Addr) {
{
Expand Down Expand Up @@ -245,13 +246,18 @@ func Verify_state1(s *stx.T, state *state1.State1) (e error) {
}
}

if state.Cur.Index == int64(44) {
i := 0
i++
}

for _, in_z := range s.Desc_Z.Ins {
if ok := state.State0.HasIn(&in_z.Nil); ok {
if ok := state.HasIn(&in_z.Nil); ok {
e = errors.New("txs.verify in already in nils")
return
} else {
}
if out, err := state.State0.GetOut(&in_z.Anchor); err != nil {
if out, err := state.GetOut(&in_z.Anchor); err != nil {
e = err
return
} else {
Expand Down
2 changes: 1 addition & 1 deletion zero/txs/txs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (self *user) Gen(seed *keys.Uint256, t *tx.T) (s stx.T, e error) {
}

func (self *user) Verify(t *stx.T) (e error) {
return Verify_state1(t, g_blocks.st1)
return Verify_state1(t, g_blocks.st1.State0)
}

func (self *user) Logout() (ret uint64) {
Expand Down
3 changes: 3 additions & 0 deletions zero/txs/zstate/state1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func CurrentState1() *State1 {

func Run(bc BlockChain) {
go run(bc)
for current_state1 != nil {
time.Sleep(time.Second * 1)
}
}

func parse_block_chain(bc BlockChain, last_cmd_count int) (current_cm_count int, e error) {
Expand Down

0 comments on commit d3b181c

Please sign in to comment.