{"record":{"id":"6e170a40a787ca9c","repo":"fish2018/pansou","slug":"anubis-w-6e170a","errorCode":null,"errorMessage":"计算 Anubis 工作量证明失败: %w","messagePattern":"计算 Anubis 工作量证明失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/miosou/miosou.go","lineNumber":281,"sourceCode":"\t}\n\tif challenge.Challenge.ID == \"\" || challenge.Challenge.RandomData == \"\" || challenge.Rules.Difficulty < 1 || challenge.Rules.Difficulty > 7 {\n\t\treturn anubisChallengeDocument{}, true, fmt.Errorf(\"Anubis 验证题目无效\")\n\t}\n\tif challenge.Rules.Algorithm != \"fast\" && challenge.Rules.Algorithm != \"slow\" {\n\t\treturn anubisChallengeDocument{}, true, fmt.Errorf(\"不支持的 Anubis 验证算法: %s\", challenge.Rules.Algorithm)\n\t}\n\treturn challenge, true, nil\n}\n\nfunc solveAnubisChallenge(ctx context.Context, randomData string, difficulty int) (string, uint64, error) {\n\tprefix := []byte(randomData)\n\tbuffer := make([]byte, len(prefix), len(prefix)+20)\n\tcopy(buffer, prefix)\n\tfor nonce := uint64(0); ; nonce++ {\n\t\tif nonce&4095 == 0 {\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\treturn \"\", 0, fmt.Errorf(\"计算 Anubis 工作量证明失败: %w\", ctx.Err())\n\t\t\tdefault:\n\t\t\t}\n\t\t}\n\t\tcandidate := strconv.AppendUint(buffer[:len(prefix)], nonce, 10)\n\t\thash := sha256.Sum256(candidate)\n\t\tif hasLeadingZeroNibbles(hash[:], difficulty) {\n\t\t\treturn hex.EncodeToString(hash[:]), nonce, nil\n\t\t}\n\t}\n}\n\nfunc hasLeadingZeroNibbles(hash []byte, difficulty int) bool {\n\tfor i := 0; i < difficulty/2; i++ {\n\t\tif hash[i] != 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn difficulty%2 == 0 || hash[difficulty/2]>>4 == 0","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/miosou/miosou.go#L263-L299","documentation":"solveAnubisChallenge brute-forces nonces until the SHA-256 of randomData+nonce has the required leading zero nibbles, checking ctx.Done() every 4096 iterations. This error wraps the context error (deadline/cancel) that aborts the PoW loop (miosou.go:281).","triggerScenarios":"The gateTimeout context expires or is cancelled while the PoW loop is still running — difficulty is too high for the hardware, or the deadline is too tight.","commonSituations":"Difficulty 5–7 on low-power devices (routers, small VPS, shared CI runners); heavily loaded CPU; too-short gateTimeout; many concurrent gate attempts starving the CPU.","solutions":["Increase gateTimeout to give slow hardware time to finish the PoW.","Reduce concurrent work while solving (run gate completion serially, avoid competing CPU load).","Upgrade the solver to check multiple nonces per hash or use a faster SHA-256 implementation / parallel workers.","Cap handled difficulty: if the challenge difficulty keeps exceeding what the host can solve in time, treat it as a server misconfiguration and report it.","Rely on ensureGate's retries — an easier challenge may be issued next attempt."],"exampleFix":"// before\nctx, cancel := context.WithTimeout(context.Background(), gateTimeout) // e.g. 5s\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) // headroom for high difficulty","handlingStrategy":"retry","validationCode":"// estimate feasibility before solving: expected hashes = 16^difficulty\nexpected := math.Pow(16, float64(difficulty))\nif expected > 1e9 {\n    return fmt.Errorf(\"difficulty %d likely exceeds CPU budget\", difficulty)\n}","typeGuard":null,"tryCatchPattern":"err := p.ensureGate()\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), \"计算 Anubis 工作量证明失败\") {\n        // PoW budget exhausted: raise gateTimeout or reduce CPU contention and retry\n    }\n    return err\n}","preventionTips":["Set gateTimeout generously for low-power hardware","Check ctx.Err() diagnostics: DeadlineExceeded vs Canceled","Avoid concurrent gate solves competing for CPU","Consider a parallel/optimized SHA-256 solver for difficulty >= 5","Cap the difficulty you attempt and report higher values as server misconfiguration"],"tags":["anubis","proof-of-work","timeout","cpu"],"backgroundTag":"request-timeout","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}