-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix test and speedup validation #3842
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,26 +333,44 @@ func (ws *workingSet) validateNonce(ctx context.Context, blk *block.Block) error | |
} | ||
appendActionIndex(accountNonceMap, caller.String(), selp.Nonce()) | ||
} | ||
return ws.checkNonceContinuity(ctx, accountNonceMap) | ||
} | ||
|
||
// Special handling for genesis block | ||
if blk.Height() == 0 { | ||
return nil | ||
func (ws *workingSet) validateNonceSkipSystemAction(ctx context.Context, blk *block.Block) error { | ||
accountNonceMap := make(map[string][]uint64) | ||
for _, selp := range blk.Actions { | ||
if action.IsSystemAction(selp) { | ||
continue | ||
} | ||
|
||
caller := selp.SenderAddress() | ||
if caller == nil { | ||
return errors.New("failed to get address") | ||
} | ||
srcAddr := caller.String() | ||
if _, ok := accountNonceMap[srcAddr]; !ok { | ||
accountNonceMap[srcAddr] = make([]uint64, 0) | ||
} | ||
accountNonceMap[srcAddr] = append(accountNonceMap[srcAddr], selp.Nonce()) | ||
} | ||
return ws.checkNonceContinuity(ctx, accountNonceMap) | ||
} | ||
|
||
func (ws *workingSet) checkNonceContinuity(ctx context.Context, accountNonceMap map[string][]uint64) error { | ||
// Verify each account's Nonce | ||
for srcAddr, receivedNonces := range accountNonceMap { | ||
addr, _ := address.FromString(srcAddr) | ||
confirmedState, err := accountutil.AccountState(ctx, ws, addr) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to get the confirmed nonce of address %s", srcAddr) | ||
} | ||
receivedNonces := receivedNonces | ||
sort.Slice(receivedNonces, func(i, j int) bool { return receivedNonces[i] < receivedNonces[j] }) | ||
pendingNonce := confirmedState.PendingNonce() | ||
for i, nonce := range receivedNonces { | ||
if nonce != pendingNonce+uint64(i) { | ||
return errors.Wrapf( | ||
action.ErrNonceTooHigh, | ||
"the %d nonce %d of address %s (init pending nonce %d) is not continuously increasing", | ||
"the %d-th nonce %d of address %s (init pending nonce %d) is not continuously increasing", | ||
i, | ||
nonce, | ||
srcAddr, | ||
|
@@ -517,8 +535,14 @@ func updateReceiptIndex(receipts []*action.Receipt) { | |
} | ||
|
||
func (ws *workingSet) ValidateBlock(ctx context.Context, blk *block.Block) error { | ||
if err := ws.validateNonce(ctx, blk); err != nil { | ||
return errors.Wrap(err, "failed to validate nonce") | ||
if protocol.MustGetFeatureCtx(ctx).SkipSystemActionNonce { | ||
if err := ws.validateNonceSkipSystemAction(ctx, blk); err != nil { | ||
return errors.Wrap(err, "failed to validate nonce") | ||
} | ||
} else { | ||
if err := ws.validateNonce(ctx, blk); err != nil { | ||
return errors.Wrap(err, "failed to validate nonce") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. block 1 has 2 tx, from the same sender
|
||
} | ||
if err := ws.process(ctx, blk.RunnableActions().Actions()); err != nil { | ||
log.L().Error("Failed to update state.", zap.Uint64("height", ws.height), zap.Error(err)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ import ( | |
func TestTimestamp(t *testing.T) { | ||
assert := assert.New(t) | ||
time1 := TimestampNow() | ||
assert.True(time.Now().After(time1)) | ||
assert.False(time.Now().Before(time1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sometimes it happens that |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnableNodeInfo
is not used at all