@typeberry/lib 0.5.10 → 0.5.11-1fbacf3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/lib/examples/pvm-usage.test.js +2 -2
- package/package.json +1 -1
- package/packages/core/codec/descriptor.js +1 -1
- package/packages/core/codec/descriptors.js +7 -4
- package/packages/core/codec/encoder.d.ts +1 -1
- package/packages/core/codec/encoder.d.ts.map +1 -1
- package/packages/core/codec/encoder.js +3 -2
- package/packages/core/codec/index.test.js +1 -1
- package/packages/core/codec/skip.d.ts +2 -1
- package/packages/core/codec/skip.d.ts.map +1 -1
- package/packages/core/codec/skip.js +3 -0
- package/packages/core/codec/view.js +2 -2
- package/packages/core/collections/multi-map.d.ts +2 -1
- package/packages/core/collections/multi-map.d.ts.map +1 -1
- package/packages/core/collections/multi-map.js +3 -0
- package/packages/core/collections/multi-map.test.js +2 -2
- package/packages/core/concurrent/parent.js +4 -1
- package/packages/core/crypto/ed25519.d.ts +2 -5
- package/packages/core/crypto/ed25519.d.ts.map +1 -1
- package/packages/core/crypto/ed25519.js +4 -1
- package/packages/core/hash/hash.d.ts +4 -2
- package/packages/core/hash/hash.d.ts.map +1 -1
- package/packages/core/hash/hash.js +6 -1
- package/packages/core/networking/quic-network.d.ts +3 -2
- package/packages/core/networking/quic-network.d.ts.map +1 -1
- package/packages/core/networking/quic-network.js +3 -0
- package/packages/core/networking/quic-peer.d.ts +2 -1
- package/packages/core/networking/quic-peer.d.ts.map +1 -1
- package/packages/core/networking/quic-peer.js +5 -2
- package/packages/core/networking/quic-stream.d.ts +2 -1
- package/packages/core/networking/quic-stream.d.ts.map +1 -1
- package/packages/core/networking/quic-stream.js +3 -0
- package/packages/core/networking/setup.js +2 -2
- package/packages/core/pvm-host-calls/bin.js +2 -2
- package/packages/core/pvm-host-calls/ecalli-trace-logger.d.ts +5 -0
- package/packages/core/pvm-host-calls/ecalli-trace-logger.d.ts.map +1 -1
- package/packages/core/pvm-host-calls/ecalli-trace-logger.js +8 -1
- package/packages/core/pvm-host-calls/ecalli-trace-logger.test.js +1 -1
- package/packages/core/pvm-host-calls/host-call-memory.d.ts +2 -1
- package/packages/core/pvm-host-calls/host-call-memory.d.ts.map +1 -1
- package/packages/core/pvm-host-calls/host-call-memory.js +3 -0
- package/packages/core/pvm-host-calls/host-call-memory.test.js +1 -1
- package/packages/core/pvm-host-calls/host-call-registers.d.ts +5 -1
- package/packages/core/pvm-host-calls/host-call-registers.d.ts.map +1 -1
- package/packages/core/pvm-host-calls/host-call-registers.js +11 -1
- package/packages/core/pvm-host-calls/host-call-registers.test.js +2 -2
- package/packages/core/pvm-host-calls/host-calls-executor.d.ts +2 -1
- package/packages/core/pvm-host-calls/host-calls-executor.d.ts.map +1 -1
- package/packages/core/pvm-host-calls/host-calls-executor.js +5 -2
- package/packages/core/pvm-host-calls/host-calls.d.ts +4 -2
- package/packages/core/pvm-host-calls/host-calls.d.ts.map +1 -1
- package/packages/core/pvm-host-calls/host-calls.js +9 -4
- package/packages/core/pvm-host-calls/pvm-instance-manager.js +1 -1
- package/packages/core/pvm-interface/pvm.d.ts +2 -0
- package/packages/core/pvm-interface/pvm.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/args-decoder/args-decoder.js +1 -1
- package/packages/core/pvm-interpreter/args-decoder/args-decoder.test.js +3 -3
- package/packages/core/pvm-interpreter/args-decoder/args-decoding-results.js +11 -11
- package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.d.ts +2 -1
- package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.js +3 -0
- package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.test.js +2 -2
- package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.d.ts +2 -1
- package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.js +3 -0
- package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.test.js +26 -26
- package/packages/core/pvm-interpreter/basic-blocks/basic-blocks.test.js +8 -8
- package/packages/core/pvm-interpreter/bin.js +1 -1
- package/packages/core/pvm-interpreter/debugger-adapter.d.ts +2 -1
- package/packages/core/pvm-interpreter/debugger-adapter.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/debugger-adapter.js +6 -3
- package/packages/core/pvm-interpreter/gas.js +4 -1
- package/packages/core/pvm-interpreter/interpreter.d.ts +2 -1
- package/packages/core/pvm-interpreter/interpreter.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/interpreter.js +19 -16
- package/packages/core/pvm-interpreter/memory/memory-builder.js +2 -2
- package/packages/core/pvm-interpreter/memory/memory-builder.test.js +7 -7
- package/packages/core/pvm-interpreter/memory/memory.d.ts +2 -1
- package/packages/core/pvm-interpreter/memory/memory.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/memory/memory.js +4 -1
- package/packages/core/pvm-interpreter/memory/memory.test.js +31 -31
- package/packages/core/pvm-interpreter/memory/pages/readable-page.d.ts +2 -1
- package/packages/core/pvm-interpreter/memory/pages/readable-page.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/memory/pages/readable-page.js +3 -0
- package/packages/core/pvm-interpreter/memory/pages/readable-page.test.js +3 -3
- package/packages/core/pvm-interpreter/memory/pages/writeable-page.d.ts +2 -1
- package/packages/core/pvm-interpreter/memory/pages/writeable-page.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/memory/pages/writeable-page.js +3 -0
- package/packages/core/pvm-interpreter/memory/pages/writeable-page.test.js +4 -4
- package/packages/core/pvm-interpreter/ops/bit-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/bit-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/bit-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/bit-ops.test.js +3 -3
- package/packages/core/pvm-interpreter/ops/bit-rotation-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/bit-rotation-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/bit-rotation-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/bit-rotation-ops.test.js +5 -5
- package/packages/core/pvm-interpreter/ops/boolean-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/boolean-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/boolean-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/boolean-ops.test.js +3 -3
- package/packages/core/pvm-interpreter/ops/branch-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/branch-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/branch-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/branch-ops.test.js +4 -4
- package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.test.js +5 -5
- package/packages/core/pvm-interpreter/ops/host-call-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/host-call-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/host-call-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/host-call-ops.test.js +2 -2
- package/packages/core/pvm-interpreter/ops/load-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/load-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/load-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/load-ops.test.js +10 -10
- package/packages/core/pvm-interpreter/ops/math-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/math-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/math-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/math-ops.test.js +3 -3
- package/packages/core/pvm-interpreter/ops/memory-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/memory-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/memory-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/memory-ops.test.js +3 -3
- package/packages/core/pvm-interpreter/ops/move-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/move-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/move-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/move-ops.test.js +3 -3
- package/packages/core/pvm-interpreter/ops/no-args-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/no-args-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/no-args-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/no-args-ops.test.js +2 -2
- package/packages/core/pvm-interpreter/ops/shift-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/shift-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/shift-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/shift-ops.test.js +3 -3
- package/packages/core/pvm-interpreter/ops/store-ops.d.ts +2 -1
- package/packages/core/pvm-interpreter/ops/store-ops.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/store-ops.js +3 -0
- package/packages/core/pvm-interpreter/ops/store-ops.test.js +7 -7
- package/packages/core/pvm-interpreter/ops-dispatchers/no-args-dispatcher.test.js +1 -1
- package/packages/core/pvm-interpreter/ops-dispatchers/one-imm-dispatcher.test.js +4 -4
- package/packages/core/pvm-interpreter/ops-dispatchers/one-offset-dispatcher.test.js +2 -2
- package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-ext-imm-dispatcher.test.js +4 -4
- package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-imm-dispatcher.test.js +7 -7
- package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-imm-one-offset-dispatcher.test.js +10 -10
- package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-two-imms-dispatcher.test.js +5 -5
- package/packages/core/pvm-interpreter/ops-dispatchers/three-regs-dispatcher.test.js +7 -7
- package/packages/core/pvm-interpreter/ops-dispatchers/two-imms-dispatcher.test.js +5 -5
- package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-dispatcher.test.js +6 -6
- package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-one-imm-dispatcher.test.js +11 -11
- package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-one-offset-dispatcher.test.js +2 -2
- package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-two-imms-dispatcher.test.js +14 -14
- package/packages/core/pvm-interpreter/program-decoder/jump-table.d.ts +5 -2
- package/packages/core/pvm-interpreter/program-decoder/jump-table.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/program-decoder/jump-table.js +9 -4
- package/packages/core/pvm-interpreter/program-decoder/jump-table.test.js +6 -6
- package/packages/core/pvm-interpreter/program-decoder/mask.d.ts +2 -1
- package/packages/core/pvm-interpreter/program-decoder/mask.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/program-decoder/mask.js +3 -0
- package/packages/core/pvm-interpreter/program-decoder/mask.test.js +10 -10
- package/packages/core/pvm-interpreter/program-decoder/program-decoder.d.ts +2 -1
- package/packages/core/pvm-interpreter/program-decoder/program-decoder.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/program-decoder/program-decoder.js +6 -3
- package/packages/core/pvm-interpreter/program-decoder/program-decoder.test.js +5 -5
- package/packages/core/pvm-interpreter/program.js +3 -3
- package/packages/core/pvm-interpreter/registers.d.ts +5 -2
- package/packages/core/pvm-interpreter/registers.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/registers.js +10 -6
- package/packages/core/pvm-interpreter/registers.test.js +10 -10
- package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.d.ts +6 -3
- package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.js +11 -2
- package/packages/core/pvm-interpreter-ananas/index.d.ts +6 -3
- package/packages/core/pvm-interpreter-ananas/index.d.ts.map +1 -1
- package/packages/core/pvm-interpreter-ananas/index.js +12 -3
- package/packages/core/trie/nodes.d.ts +7 -2
- package/packages/core/trie/nodes.d.ts.map +1 -1
- package/packages/core/trie/nodes.js +20 -11
- package/packages/core/trie/nodesDb.d.ts +3 -1
- package/packages/core/trie/nodesDb.d.ts.map +1 -1
- package/packages/core/trie/nodesDb.js +6 -0
- package/packages/core/trie/trie.js +2 -2
- package/packages/extensions/ipc/index.js +5 -2
- package/packages/extensions/ipc/jamnp/handler.d.ts +4 -2
- package/packages/extensions/ipc/jamnp/handler.d.ts.map +1 -1
- package/packages/extensions/ipc/jamnp/handler.js +9 -3
- package/packages/extensions/ipc/jamnp/server.js +3 -3
- package/packages/extensions/ipc/server.d.ts +2 -1
- package/packages/extensions/ipc/server.d.ts.map +1 -1
- package/packages/extensions/ipc/server.js +4 -1
- package/packages/jam/block/header.js +1 -1
- package/packages/jam/block/work-package.d.ts +7 -7
- package/packages/jam/block/work-package.d.ts.map +1 -1
- package/packages/jam/block/work-package.js +12 -12
- package/packages/jam/config/chain-spec.d.ts +2 -1
- package/packages/jam/config/chain-spec.d.ts.map +1 -1
- package/packages/jam/config/chain-spec.js +5 -2
- package/packages/jam/config/network.d.ts +2 -7
- package/packages/jam/config/network.d.ts.map +1 -1
- package/packages/jam/config/network.js +3 -0
- package/packages/jam/config-node/jip-chain-spec.js +1 -1
- package/packages/jam/database/blocks.test.js +1 -1
- package/packages/jam/database/states.d.ts +2 -1
- package/packages/jam/database/states.d.ts.map +1 -1
- package/packages/jam/database/states.js +3 -0
- package/packages/jam/database/states.test.js +1 -1
- package/packages/jam/database-lmdb/blocks.d.ts +2 -1
- package/packages/jam/database-lmdb/blocks.d.ts.map +1 -1
- package/packages/jam/database-lmdb/blocks.js +3 -0
- package/packages/jam/database-lmdb/root.d.ts +2 -1
- package/packages/jam/database-lmdb/root.d.ts.map +1 -1
- package/packages/jam/database-lmdb/root.js +3 -0
- package/packages/jam/database-lmdb/states.d.ts +2 -1
- package/packages/jam/database-lmdb/states.d.ts.map +1 -1
- package/packages/jam/database-lmdb/states.js +3 -0
- package/packages/jam/database-lmdb/states.test.js +9 -9
- package/packages/jam/executor/index.d.ts +1 -1
- package/packages/jam/executor/index.d.ts.map +1 -1
- package/packages/jam/executor/index.js +1 -1
- package/packages/jam/executor/pvm-executor.d.ts +9 -2
- package/packages/jam/executor/pvm-executor.d.ts.map +1 -1
- package/packages/jam/executor/pvm-executor.js +36 -21
- package/packages/jam/fuzz-proto/v1/handler.d.ts +2 -1
- package/packages/jam/fuzz-proto/v1/handler.d.ts.map +1 -1
- package/packages/jam/fuzz-proto/v1/handler.js +3 -0
- package/packages/jam/fuzz-proto/v1/handler.test.js +10 -10
- package/packages/jam/in-core/externalities/index.d.ts +4 -0
- package/packages/jam/in-core/externalities/index.d.ts.map +1 -0
- package/packages/jam/in-core/externalities/index.js +3 -0
- package/packages/jam/in-core/externalities/is-authorized-fetch.d.ts +20 -0
- package/packages/jam/in-core/externalities/is-authorized-fetch.d.ts.map +1 -0
- package/packages/jam/in-core/externalities/is-authorized-fetch.js +41 -0
- package/packages/jam/in-core/externalities/is-authorized-fetch.test.d.ts +2 -0
- package/packages/jam/in-core/externalities/is-authorized-fetch.test.d.ts.map +1 -0
- package/packages/jam/in-core/externalities/is-authorized-fetch.test.js +101 -0
- package/packages/jam/in-core/externalities/refine-fetch.d.ts +51 -0
- package/packages/jam/in-core/externalities/refine-fetch.d.ts.map +1 -0
- package/packages/jam/in-core/externalities/refine-fetch.js +80 -0
- package/packages/jam/in-core/externalities/refine-fetch.test.d.ts +2 -0
- package/packages/jam/in-core/externalities/refine-fetch.test.d.ts.map +1 -0
- package/packages/jam/in-core/externalities/refine-fetch.test.js +219 -0
- package/packages/jam/in-core/externalities/refine.d.ts +18 -8
- package/packages/jam/in-core/externalities/refine.d.ts.map +1 -1
- package/packages/jam/in-core/externalities/refine.js +86 -7
- package/packages/jam/in-core/externalities/refine.test.js +168 -3
- package/packages/jam/in-core/in-core.d.ts +9 -23
- package/packages/jam/in-core/in-core.d.ts.map +1 -1
- package/packages/jam/in-core/in-core.js +22 -187
- package/packages/jam/in-core/in-core.test.js +52 -20
- package/packages/jam/in-core/is-authorized.d.ts +34 -0
- package/packages/jam/in-core/is-authorized.d.ts.map +1 -0
- package/packages/jam/in-core/is-authorized.js +73 -0
- package/packages/jam/in-core/is-authorized.test.d.ts +2 -0
- package/packages/jam/in-core/is-authorized.test.d.ts.map +1 -0
- package/packages/jam/in-core/is-authorized.test.js +167 -0
- package/packages/jam/in-core/refine.d.ts +31 -0
- package/packages/jam/in-core/refine.d.ts.map +1 -0
- package/packages/jam/in-core/refine.js +182 -0
- package/packages/jam/in-core/refine.test.d.ts +2 -0
- package/packages/jam/in-core/refine.test.d.ts.map +1 -0
- package/packages/jam/in-core/refine.test.js +6 -0
- package/packages/jam/jam-host-calls/accumulate/assign.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/assign.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/assign.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/assign.test.js +8 -9
- package/packages/jam/jam-host-calls/accumulate/bless.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/bless.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/bless.js +12 -9
- package/packages/jam/jam-host-calls/accumulate/bless.test.js +11 -12
- package/packages/jam/jam-host-calls/accumulate/checkpoint.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/checkpoint.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/checkpoint.js +4 -1
- package/packages/jam/jam-host-calls/accumulate/checkpoint.test.js +2 -3
- package/packages/jam/jam-host-calls/accumulate/designate.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/designate.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/designate.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/designate.test.js +5 -6
- package/packages/jam/jam-host-calls/accumulate/eject.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/eject.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/eject.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/eject.test.js +8 -9
- package/packages/jam/jam-host-calls/accumulate/forget.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/forget.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/forget.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/forget.test.js +5 -6
- package/packages/jam/jam-host-calls/accumulate/new.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/new.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/new.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/new.test.js +9 -10
- package/packages/jam/jam-host-calls/accumulate/provide.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/provide.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/provide.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/provide.test.js +8 -9
- package/packages/jam/jam-host-calls/accumulate/query.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/query.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/query.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/query.test.js +8 -9
- package/packages/jam/jam-host-calls/accumulate/solicit.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/solicit.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/solicit.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/solicit.test.js +7 -8
- package/packages/jam/jam-host-calls/accumulate/transfer.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/transfer.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/transfer.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/transfer.test.js +9 -10
- package/packages/jam/jam-host-calls/accumulate/upgrade.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/upgrade.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/upgrade.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/upgrade.test.js +4 -5
- package/packages/jam/jam-host-calls/accumulate/yield.d.ts +2 -1
- package/packages/jam/jam-host-calls/accumulate/yield.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/yield.js +3 -0
- package/packages/jam/jam-host-calls/accumulate/yield.test.js +4 -5
- package/packages/jam/jam-host-calls/externalities/partial-state.d.ts +1 -1
- package/packages/jam/jam-host-calls/externalities/refine-externalities.d.ts +1 -1
- package/packages/jam/jam-host-calls/externalities/refine-externalities.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/externalities/refine-externalities.test.js +9 -9
- package/packages/jam/jam-host-calls/externalities/state-update.d.ts +2 -3
- package/packages/jam/jam-host-calls/externalities/state-update.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/externalities/state-update.js +5 -2
- package/packages/jam/jam-host-calls/externalities/test-accounts.js +2 -2
- package/packages/jam/jam-host-calls/general/fetch.d.ts +166 -104
- package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/fetch.js +120 -23
- package/packages/jam/jam-host-calls/general/fetch.test.js +125 -92
- package/packages/jam/jam-host-calls/general/gas.d.ts +2 -1
- package/packages/jam/jam-host-calls/general/gas.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/gas.js +3 -0
- package/packages/jam/jam-host-calls/general/gas.test.js +4 -5
- package/packages/jam/jam-host-calls/general/info.d.ts +2 -1
- package/packages/jam/jam-host-calls/general/info.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/info.js +3 -0
- package/packages/jam/jam-host-calls/general/info.test.js +6 -7
- package/packages/jam/jam-host-calls/general/log.d.ts +2 -1
- package/packages/jam/jam-host-calls/general/log.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/log.js +3 -0
- package/packages/jam/jam-host-calls/general/lookup.d.ts +2 -1
- package/packages/jam/jam-host-calls/general/lookup.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/lookup.js +3 -0
- package/packages/jam/jam-host-calls/general/lookup.test.js +8 -9
- package/packages/jam/jam-host-calls/general/read.d.ts +2 -1
- package/packages/jam/jam-host-calls/general/read.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/read.js +3 -0
- package/packages/jam/jam-host-calls/general/read.test.js +11 -12
- package/packages/jam/jam-host-calls/general/write.d.ts +2 -1
- package/packages/jam/jam-host-calls/general/write.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/write.js +3 -0
- package/packages/jam/jam-host-calls/general/write.test.js +10 -11
- package/packages/jam/jam-host-calls/refine/export.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/export.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/export.js +3 -0
- package/packages/jam/jam-host-calls/refine/export.test.js +6 -7
- package/packages/jam/jam-host-calls/refine/expunge.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/expunge.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/expunge.js +3 -0
- package/packages/jam/jam-host-calls/refine/expunge.test.js +3 -4
- package/packages/jam/jam-host-calls/refine/historical-lookup.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/historical-lookup.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/historical-lookup.js +3 -0
- package/packages/jam/jam-host-calls/refine/historical-lookup.test.js +11 -12
- package/packages/jam/jam-host-calls/refine/invoke.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/invoke.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/invoke.js +4 -1
- package/packages/jam/jam-host-calls/refine/invoke.test.js +10 -11
- package/packages/jam/jam-host-calls/refine/machine.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/machine.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/machine.js +3 -0
- package/packages/jam/jam-host-calls/refine/machine.test.js +6 -7
- package/packages/jam/jam-host-calls/refine/pages.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/pages.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/pages.js +3 -0
- package/packages/jam/jam-host-calls/refine/pages.test.js +3 -4
- package/packages/jam/jam-host-calls/refine/peek.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/peek.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/peek.js +3 -0
- package/packages/jam/jam-host-calls/refine/peek.test.js +3 -4
- package/packages/jam/jam-host-calls/refine/poke.d.ts +2 -1
- package/packages/jam/jam-host-calls/refine/poke.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/refine/poke.js +3 -0
- package/packages/jam/jam-host-calls/refine/poke.test.js +3 -4
- package/packages/jam/jamnp-s/network.js +1 -1
- package/packages/jam/jamnp-s/peers.d.ts +2 -1
- package/packages/jam/jamnp-s/peers.d.ts.map +1 -1
- package/packages/jam/jamnp-s/peers.js +3 -0
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts +4 -2
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.js +6 -0
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.test.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts +4 -2
- package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-129-state-request.js +6 -0
- package/packages/jam/jamnp-s/protocol/ce-129-state-request.test.js +4 -4
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts +4 -2
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.js +6 -0
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.test.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +6 -3
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.js +7 -0
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.test.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts +5 -2
- package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.js +7 -0
- package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.test.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts +4 -2
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.js +6 -0
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.test.js +2 -2
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts +2 -1
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.js +3 -0
- package/packages/jam/jamnp-s/stream-manager.d.ts +2 -1
- package/packages/jam/jamnp-s/stream-manager.d.ts.map +1 -1
- package/packages/jam/jamnp-s/stream-manager.js +4 -1
- package/packages/jam/jamnp-s/tasks/sync.js +4 -4
- package/packages/jam/jamnp-s/tasks/sync.test.js +4 -4
- package/packages/jam/jamnp-s/tasks/ticket-distribution.js +2 -2
- package/packages/jam/jamnp-s/tasks/ticket-distribution.test.js +1 -1
- package/packages/jam/node/common.d.ts.map +1 -1
- package/packages/jam/node/common.js +3 -3
- package/packages/jam/rpc-client/index.d.ts +4 -2
- package/packages/jam/rpc-client/index.d.ts.map +1 -1
- package/packages/jam/rpc-client/index.js +7 -1
- package/packages/jam/state/in-memory-state-view.d.ts +2 -1
- package/packages/jam/state/in-memory-state-view.d.ts.map +1 -1
- package/packages/jam/state/in-memory-state-view.js +3 -0
- package/packages/jam/state/in-memory-state.d.ts +16 -21
- package/packages/jam/state/in-memory-state.d.ts.map +1 -1
- package/packages/jam/state/in-memory-state.js +10 -6
- package/packages/jam/state/in-memory-state.test.js +2 -2
- package/packages/jam/state/service.d.ts +2 -6
- package/packages/jam/state/service.d.ts.map +1 -1
- package/packages/jam/state/service.js +3 -0
- package/packages/jam/state/test.utils.js +3 -3
- package/packages/jam/state-json/accounts.js +5 -5
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts +3 -34
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts.map +1 -1
- package/packages/jam/state-merkleization/in-memory-state-codec.js +1 -1
- package/packages/jam/state-merkleization/serialized-state-view.d.ts +8 -3
- package/packages/jam/state-merkleization/serialized-state-view.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialized-state-view.js +6 -3
- package/packages/jam/state-merkleization/serialized-state.d.ts +2 -3
- package/packages/jam/state-merkleization/serialized-state.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialized-state.js +10 -2
- package/packages/jam/state-merkleization/serialized-state.test.js +1 -1
- package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate.js +20 -8
- package/packages/jam/transition/accumulate/accumulate.test.js +1 -1
- package/packages/jam/transition/accumulate/accumulation-result-merge-utils.js +48 -39
- package/packages/jam/transition/block-verifier.d.ts +2 -1
- package/packages/jam/transition/block-verifier.d.ts.map +1 -1
- package/packages/jam/transition/block-verifier.js +3 -0
- package/packages/jam/transition/block-verifier.test.js +8 -8
- package/packages/jam/transition/chain-stf.d.ts +12 -4
- package/packages/jam/transition/chain-stf.d.ts.map +1 -1
- package/packages/jam/transition/chain-stf.js +7 -3
- package/packages/jam/transition/externalities/accumulate-externalities.d.ts +22 -8
- package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/accumulate-externalities.js +49 -29
- package/packages/jam/transition/externalities/accumulate-externalities.test.js +661 -101
- package/packages/jam/transition/externalities/accumulate-fetch-externalities.d.ts +19 -0
- package/packages/jam/transition/externalities/accumulate-fetch-externalities.d.ts.map +1 -0
- package/packages/jam/transition/externalities/accumulate-fetch-externalities.js +45 -0
- package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.d.ts +2 -0
- package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.d.ts.map +1 -0
- package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.js +192 -0
- package/packages/jam/transition/externalities/fetch-externalities.d.ts +54 -37
- package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/fetch-externalities.js +45 -89
- package/packages/jam/transition/externalities/index.d.ts +1 -0
- package/packages/jam/transition/externalities/index.d.ts.map +1 -1
- package/packages/jam/transition/externalities/index.js +1 -0
- package/packages/jam/transition/hasher.d.ts +2 -1
- package/packages/jam/transition/hasher.d.ts.map +1 -1
- package/packages/jam/transition/hasher.js +5 -2
- package/packages/jam/transition/hasher.test.js +1 -1
- package/packages/jam/transition/preimages.test.js +4 -4
- package/packages/jam/transition/reports/test.utils.js +1 -1
- package/packages/workers/api-node/config.js +4 -4
- package/packages/workers/api-node/port.d.ts +2 -1
- package/packages/workers/api-node/port.d.ts.map +1 -1
- package/packages/workers/api-node/port.js +4 -1
- package/packages/workers/api-node/port.test.js +2 -2
- package/packages/workers/api-node/protocol.js +2 -2
- package/packages/workers/block-authorship/generator.d.ts +13 -2
- package/packages/workers/block-authorship/generator.d.ts.map +1 -1
- package/packages/workers/block-authorship/generator.js +13 -9
- package/packages/workers/block-authorship/generator.test.js +16 -2
- package/packages/workers/block-authorship/main.d.ts.map +1 -1
- package/packages/workers/block-authorship/main.js +8 -1
- package/packages/workers/importer/finality.test.js +1 -1
- package/packages/workers/importer/importer.d.ts +23 -6
- package/packages/workers/importer/importer.d.ts.map +1 -1
- package/packages/workers/importer/importer.js +34 -19
- package/packages/workers/importer/main.d.ts.map +1 -1
- package/packages/workers/importer/main.js +13 -5
- package/packages/jam/transition/externalities/fetch-externalities.test.d.ts +0 -2
- package/packages/jam/transition/externalities/fetch-externalities.test.d.ts.map +0 -1
- package/packages/jam/transition/externalities/fetch-externalities.test.js +0 -254
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Bytes } from "#@typeberry/bytes";
|
|
2
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
3
|
+
import { general } from "#@typeberry/jam-host-calls";
|
|
4
|
+
import { getEncodedConstants, u64ToArrayIndex, } from "#@typeberry/transition/externalities/fetch-externalities.js";
|
|
5
|
+
export class RefineFetchExternalities {
|
|
6
|
+
chainSpec;
|
|
7
|
+
data;
|
|
8
|
+
context = general.FetchContext.Refine;
|
|
9
|
+
constructor(chainSpec, data) {
|
|
10
|
+
this.chainSpec = chainSpec;
|
|
11
|
+
this.data = data;
|
|
12
|
+
}
|
|
13
|
+
constants() {
|
|
14
|
+
return getEncodedConstants(this.chainSpec);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Refine entropy is `H₀` (zero hash) per GP §B.3.
|
|
18
|
+
*
|
|
19
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/2fe0012fe201?v=0.7.2
|
|
20
|
+
*/
|
|
21
|
+
entropy() {
|
|
22
|
+
return Bytes.zero(HASH_SIZE).asOpaque();
|
|
23
|
+
}
|
|
24
|
+
authorizerTrace() {
|
|
25
|
+
return this.data.authorizerTrace;
|
|
26
|
+
}
|
|
27
|
+
workItemExtrinsic(workItem, index) {
|
|
28
|
+
const itemIdx = workItem === null ? this.data.currentWorkItemIndex : u64ToArrayIndex(workItem, this.data.extrinsics.length);
|
|
29
|
+
if (itemIdx === null) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const perItem = this.data.extrinsics[itemIdx];
|
|
33
|
+
const xIdx = u64ToArrayIndex(index, perItem.length);
|
|
34
|
+
if (xIdx === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return perItem[xIdx];
|
|
38
|
+
}
|
|
39
|
+
workItemImport(workItem, index) {
|
|
40
|
+
const itemIdx = workItem === null ? this.data.currentWorkItemIndex : u64ToArrayIndex(workItem, this.data.imports.length);
|
|
41
|
+
if (itemIdx === null) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const perItem = this.data.imports[itemIdx];
|
|
45
|
+
const segIdx = u64ToArrayIndex(index, perItem.length);
|
|
46
|
+
if (segIdx === null) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// `Segment` extends `BytesBlob`, so it can be returned directly.
|
|
50
|
+
return perItem[segIdx].data;
|
|
51
|
+
}
|
|
52
|
+
workPackage() {
|
|
53
|
+
return this.data.packageData.packageView.encoded();
|
|
54
|
+
}
|
|
55
|
+
authConfiguration() {
|
|
56
|
+
return this.data.packageData.packageView.authConfiguration.view();
|
|
57
|
+
}
|
|
58
|
+
authToken() {
|
|
59
|
+
return this.data.packageData.packageView.authToken.view();
|
|
60
|
+
}
|
|
61
|
+
refineContext() {
|
|
62
|
+
return this.data.packageData.packageView.context.encoded();
|
|
63
|
+
}
|
|
64
|
+
allWorkItems() {
|
|
65
|
+
return this.data.packageData.workItemSummaries.encoded();
|
|
66
|
+
}
|
|
67
|
+
oneWorkItem(workItem) {
|
|
68
|
+
const summaries = this.data.packageData.workItemSummaries;
|
|
69
|
+
const idx = u64ToArrayIndex(workItem, summaries.length);
|
|
70
|
+
return idx === null ? null : (summaries.get(idx)?.encoded() ?? null);
|
|
71
|
+
}
|
|
72
|
+
workItemPayload(workItem) {
|
|
73
|
+
const items = this.data.packageData.packageView.items.view();
|
|
74
|
+
const idx = u64ToArrayIndex(workItem, items.length);
|
|
75
|
+
if (idx === null) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return items.get(idx)?.view().payload.view() ?? null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refine-fetch.test.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/in-core/externalities/refine-fetch.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { tryAsServiceGas, tryAsServiceId, tryAsTimeSlot } from "#@typeberry/block";
|
|
4
|
+
import { RefineContext } from "#@typeberry/block/refine-context.js";
|
|
5
|
+
import { ImportSpec, WorkItem, WorkItemExtrinsicSpec } from "#@typeberry/block/work-item.js";
|
|
6
|
+
import { SEGMENT_BYTES, tryAsSegmentIndex } from "#@typeberry/block/work-item-segment.js";
|
|
7
|
+
import { tryAsWorkItemsCount, WorkPackage } from "#@typeberry/block/work-package.js";
|
|
8
|
+
import { Bytes, BytesBlob } from "#@typeberry/bytes";
|
|
9
|
+
import { Encoder } from "#@typeberry/codec";
|
|
10
|
+
import { asKnownSize, FixedSizeArray } from "#@typeberry/collections";
|
|
11
|
+
import { fullChainSpec, tinyChainSpec } from "#@typeberry/config";
|
|
12
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
13
|
+
import { tryAsU16, tryAsU32, tryAsU64 } from "#@typeberry/numbers";
|
|
14
|
+
import { buildWorkPackageFetchData } from "#@typeberry/transition/externalities/fetch-externalities.js";
|
|
15
|
+
import { asOpaqueType } from "#@typeberry/utils";
|
|
16
|
+
import { RefineFetchExternalities } from "./refine-fetch.js";
|
|
17
|
+
const asExtrinsic = (bytes) => asOpaqueType(bytes);
|
|
18
|
+
function buildWorkItem(overrides) {
|
|
19
|
+
const codeHash = Bytes.fill(HASH_SIZE, 7).asOpaque();
|
|
20
|
+
const imports = Array.from({ length: overrides.importCount ?? 0 }, (_, i) => ImportSpec.create({ treeRoot: Bytes.zero(HASH_SIZE), index: tryAsSegmentIndex(i) }));
|
|
21
|
+
const extrinsicSpecs = Array.from({ length: overrides.extrinsicCount ?? 0 }, () => WorkItemExtrinsicSpec.create({ hash: Bytes.zero(HASH_SIZE).asOpaque(), len: tryAsU32(0) }));
|
|
22
|
+
return WorkItem.create({
|
|
23
|
+
service: tryAsServiceId(overrides.service ?? 1),
|
|
24
|
+
codeHash,
|
|
25
|
+
payload: BytesBlob.blobFrom(new Uint8Array(overrides.payloadLen ?? 3).fill(0xab)),
|
|
26
|
+
refineGasLimit: tryAsServiceGas(1_000_000),
|
|
27
|
+
accumulateGasLimit: tryAsServiceGas(2_000_000),
|
|
28
|
+
importSegments: asKnownSize(imports),
|
|
29
|
+
extrinsic: extrinsicSpecs,
|
|
30
|
+
exportCount: tryAsU16(overrides.exportCount ?? 0),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function buildWorkPackage(items) {
|
|
34
|
+
return WorkPackage.create({
|
|
35
|
+
authToken: BytesBlob.blobFrom(new Uint8Array([1, 2, 3])),
|
|
36
|
+
authCodeHost: tryAsServiceId(42),
|
|
37
|
+
authCodeHash: Bytes.fill(HASH_SIZE, 9).asOpaque(),
|
|
38
|
+
authConfiguration: BytesBlob.blobFrom(new Uint8Array([4, 5, 6, 7])),
|
|
39
|
+
context: RefineContext.create({
|
|
40
|
+
anchor: Bytes.fill(HASH_SIZE, 1).asOpaque(),
|
|
41
|
+
stateRoot: Bytes.fill(HASH_SIZE, 2).asOpaque(),
|
|
42
|
+
beefyRoot: Bytes.fill(HASH_SIZE, 3).asOpaque(),
|
|
43
|
+
lookupAnchor: Bytes.fill(HASH_SIZE, 4).asOpaque(),
|
|
44
|
+
lookupAnchorSlot: tryAsTimeSlot(16),
|
|
45
|
+
prerequisites: [],
|
|
46
|
+
}),
|
|
47
|
+
items: FixedSizeArray.new(items, tryAsWorkItemsCount(items.length)),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function prepareRefineData(opts = {}) {
|
|
51
|
+
const chainSpec = opts.chainSpec ?? tinyChainSpec;
|
|
52
|
+
const items = opts.items ?? [buildWorkItem({})];
|
|
53
|
+
const workPackage = buildWorkPackage(items);
|
|
54
|
+
const packageData = buildWorkPackageFetchData(chainSpec, workPackage);
|
|
55
|
+
return new RefineFetchExternalities(chainSpec, {
|
|
56
|
+
packageData,
|
|
57
|
+
currentWorkItemIndex: opts.currentWorkItemIndex ?? 0,
|
|
58
|
+
imports: opts.imports ?? asKnownSize(items.map(() => [])),
|
|
59
|
+
extrinsics: opts.extrinsics ?? asKnownSize(items.map(() => [])),
|
|
60
|
+
authorizerTrace: opts.authorizerTrace ?? BytesBlob.empty(),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
describe("RefineFetchExternalities", () => {
|
|
64
|
+
it("should return different constants for different chain specs", () => {
|
|
65
|
+
const tinyExt = prepareRefineData({ chainSpec: tinyChainSpec });
|
|
66
|
+
const fullExt = prepareRefineData({ chainSpec: fullChainSpec });
|
|
67
|
+
assert.notStrictEqual(tinyExt.constants().length, 0);
|
|
68
|
+
assert.notStrictEqual(fullExt.constants().length, 0);
|
|
69
|
+
assert.notDeepStrictEqual(tinyExt.constants(), fullExt.constants());
|
|
70
|
+
});
|
|
71
|
+
it("should return entropy H_0 (zero hash) per GP §B.3", () => {
|
|
72
|
+
const ext = prepareRefineData();
|
|
73
|
+
const entropy = ext.entropy();
|
|
74
|
+
assert.strictEqual(entropy.length, HASH_SIZE);
|
|
75
|
+
assert.ok(entropy.isEqualTo(Bytes.zero(HASH_SIZE).asOpaque()));
|
|
76
|
+
});
|
|
77
|
+
it("should return the supplied authorizer trace", () => {
|
|
78
|
+
const trace = BytesBlob.blobFrom(new Uint8Array([0xaa, 0xbb, 0xcc]));
|
|
79
|
+
const ext = prepareRefineData({ authorizerTrace: trace });
|
|
80
|
+
assert.deepStrictEqual(ext.authorizerTrace().raw, trace.raw);
|
|
81
|
+
});
|
|
82
|
+
it("should return an extrinsic by work item index and extrinsic index", () => {
|
|
83
|
+
const items = [buildWorkItem({}), buildWorkItem({ service: 2 })];
|
|
84
|
+
const extrinsics = asKnownSize([
|
|
85
|
+
[asExtrinsic(BytesBlob.blobFrom(new Uint8Array([1])))],
|
|
86
|
+
[
|
|
87
|
+
asExtrinsic(BytesBlob.blobFrom(new Uint8Array([2, 2]))),
|
|
88
|
+
asExtrinsic(BytesBlob.blobFrom(new Uint8Array([3, 3, 3]))),
|
|
89
|
+
],
|
|
90
|
+
]);
|
|
91
|
+
const ext = prepareRefineData({ items, extrinsics });
|
|
92
|
+
const other = ext.workItemExtrinsic(tryAsU64(1), tryAsU64(1));
|
|
93
|
+
assert.ok(other !== null);
|
|
94
|
+
assert.deepStrictEqual(other.raw, new Uint8Array([3, 3, 3]));
|
|
95
|
+
});
|
|
96
|
+
it("should return current item's extrinsic when workItem is null", () => {
|
|
97
|
+
const items = [buildWorkItem({}), buildWorkItem({ service: 2 })];
|
|
98
|
+
const extrinsics = asKnownSize([
|
|
99
|
+
[asExtrinsic(BytesBlob.blobFrom(new Uint8Array([9])))],
|
|
100
|
+
[asExtrinsic(BytesBlob.blobFrom(new Uint8Array([8])))],
|
|
101
|
+
]);
|
|
102
|
+
const ext = prepareRefineData({ items, extrinsics, currentWorkItemIndex: 1 });
|
|
103
|
+
const mine = ext.workItemExtrinsic(null, tryAsU64(0));
|
|
104
|
+
assert.ok(mine !== null);
|
|
105
|
+
assert.deepStrictEqual(mine.raw, new Uint8Array([8]));
|
|
106
|
+
});
|
|
107
|
+
it("should return null for out-of-range extrinsic indices", () => {
|
|
108
|
+
const items = [buildWorkItem({})];
|
|
109
|
+
const extrinsics = asKnownSize([
|
|
110
|
+
[asExtrinsic(BytesBlob.blobFrom(new Uint8Array([1])))],
|
|
111
|
+
]);
|
|
112
|
+
const ext = prepareRefineData({ items, extrinsics });
|
|
113
|
+
assert.strictEqual(ext.workItemExtrinsic(tryAsU64(5), tryAsU64(0)), null);
|
|
114
|
+
assert.strictEqual(ext.workItemExtrinsic(tryAsU64(0), tryAsU64(5)), null);
|
|
115
|
+
assert.strictEqual(ext.workItemExtrinsic(null, tryAsU64(5)), null);
|
|
116
|
+
});
|
|
117
|
+
it("should treat U64 indices above the safe-integer range as out of range", () => {
|
|
118
|
+
const items = [buildWorkItem({})];
|
|
119
|
+
const ext = prepareRefineData({ items });
|
|
120
|
+
const huge = tryAsU64(2n ** 53n); // first value > Number.MAX_SAFE_INTEGER
|
|
121
|
+
assert.strictEqual(ext.workItemExtrinsic(huge, tryAsU64(0)), null);
|
|
122
|
+
assert.strictEqual(ext.workItemExtrinsic(null, huge), null);
|
|
123
|
+
assert.strictEqual(ext.workItemImport(huge, tryAsU64(0)), null);
|
|
124
|
+
assert.strictEqual(ext.oneWorkItem(huge), null);
|
|
125
|
+
assert.strictEqual(ext.workItemPayload(huge), null);
|
|
126
|
+
});
|
|
127
|
+
it("should return an import segment by work item index and segment index", () => {
|
|
128
|
+
const items = [buildWorkItem({}), buildWorkItem({ service: 2 })];
|
|
129
|
+
const segBytes = new Uint8Array(SEGMENT_BYTES).fill(0x55);
|
|
130
|
+
const imports = asKnownSize([
|
|
131
|
+
[],
|
|
132
|
+
[{ index: tryAsSegmentIndex(0), data: Bytes.fromBlob(segBytes, SEGMENT_BYTES) }],
|
|
133
|
+
]);
|
|
134
|
+
const ext = prepareRefineData({ items, imports });
|
|
135
|
+
const imp = ext.workItemImport(tryAsU64(1), tryAsU64(0));
|
|
136
|
+
assert.ok(imp !== null);
|
|
137
|
+
assert.deepStrictEqual(imp.raw, segBytes);
|
|
138
|
+
});
|
|
139
|
+
it("should return null for out-of-range import indices", () => {
|
|
140
|
+
const ext = prepareRefineData();
|
|
141
|
+
assert.strictEqual(ext.workItemImport(tryAsU64(10), tryAsU64(0)), null);
|
|
142
|
+
assert.strictEqual(ext.workItemImport(null, tryAsU64(10)), null);
|
|
143
|
+
assert.strictEqual(ext.workItemImport(tryAsU64(0), tryAsU64(10)), null);
|
|
144
|
+
});
|
|
145
|
+
it("should return encoded work package", () => {
|
|
146
|
+
const items = [buildWorkItem({})];
|
|
147
|
+
const ext = prepareRefineData({ items });
|
|
148
|
+
const expected = Encoder.encodeObject(WorkPackage.Codec, buildWorkPackage(items), tinyChainSpec);
|
|
149
|
+
assert.deepStrictEqual(ext.workPackage().raw, expected.raw);
|
|
150
|
+
});
|
|
151
|
+
it("should return auth configuration and auth token from the package", () => {
|
|
152
|
+
const ext = prepareRefineData();
|
|
153
|
+
assert.deepStrictEqual(ext.authConfiguration().raw, new Uint8Array([4, 5, 6, 7]));
|
|
154
|
+
assert.deepStrictEqual(ext.authToken().raw, new Uint8Array([1, 2, 3]));
|
|
155
|
+
});
|
|
156
|
+
it("should return encoded refine context", () => {
|
|
157
|
+
const ext = prepareRefineData();
|
|
158
|
+
const context = RefineContext.create({
|
|
159
|
+
anchor: Bytes.fill(HASH_SIZE, 1).asOpaque(),
|
|
160
|
+
stateRoot: Bytes.fill(HASH_SIZE, 2).asOpaque(),
|
|
161
|
+
beefyRoot: Bytes.fill(HASH_SIZE, 3).asOpaque(),
|
|
162
|
+
lookupAnchor: Bytes.fill(HASH_SIZE, 4).asOpaque(),
|
|
163
|
+
lookupAnchorSlot: tryAsTimeSlot(16),
|
|
164
|
+
prerequisites: [],
|
|
165
|
+
});
|
|
166
|
+
const expected = Encoder.encodeObject(RefineContext.Codec, context);
|
|
167
|
+
assert.deepStrictEqual(ext.refineContext().raw, expected.raw);
|
|
168
|
+
});
|
|
169
|
+
it("should return concatenated work item summaries (kind 11) with 62 bytes per item", () => {
|
|
170
|
+
const items = [
|
|
171
|
+
buildWorkItem({ service: 1, payloadLen: 7, exportCount: 2, importCount: 1, extrinsicCount: 0 }),
|
|
172
|
+
buildWorkItem({ service: 2, payloadLen: 4, exportCount: 0, importCount: 0, extrinsicCount: 3 }),
|
|
173
|
+
];
|
|
174
|
+
const ext = prepareRefineData({ items });
|
|
175
|
+
const all = ext.allWorkItems();
|
|
176
|
+
assert.strictEqual(all.length, 62 * items.length);
|
|
177
|
+
});
|
|
178
|
+
it("should return a single work item summary (kind 12)", () => {
|
|
179
|
+
const items = [buildWorkItem({ service: 1 }), buildWorkItem({ service: 2, payloadLen: 10 })];
|
|
180
|
+
const ext = prepareRefineData({ items });
|
|
181
|
+
const one = ext.oneWorkItem(tryAsU64(1));
|
|
182
|
+
assert.ok(one !== null);
|
|
183
|
+
assert.strictEqual(one.length, 62);
|
|
184
|
+
// first 4 bytes are the service id (u32 LE).
|
|
185
|
+
const serviceId = new DataView(one.raw.buffer, one.raw.byteOffset, 4).getUint32(0, true);
|
|
186
|
+
assert.strictEqual(serviceId, 2);
|
|
187
|
+
// payload length is the last 4 bytes (u32 LE).
|
|
188
|
+
const payloadLen = new DataView(one.raw.buffer, one.raw.byteOffset + 58, 4).getUint32(0, true);
|
|
189
|
+
assert.strictEqual(payloadLen, 10);
|
|
190
|
+
});
|
|
191
|
+
it("should return null for one work item when index is out of range", () => {
|
|
192
|
+
const ext = prepareRefineData();
|
|
193
|
+
assert.strictEqual(ext.oneWorkItem(tryAsU64(99)), null);
|
|
194
|
+
});
|
|
195
|
+
it("should return the raw payload of a work item (kind 13)", () => {
|
|
196
|
+
const items = [buildWorkItem({ service: 1, payloadLen: 2 }), buildWorkItem({ service: 2, payloadLen: 5 })];
|
|
197
|
+
const ext = prepareRefineData({ items });
|
|
198
|
+
const payload = ext.workItemPayload(tryAsU64(1));
|
|
199
|
+
assert.ok(payload !== null);
|
|
200
|
+
assert.strictEqual(payload.length, 5);
|
|
201
|
+
assert.ok(payload.raw.every((x) => x === 0xab));
|
|
202
|
+
});
|
|
203
|
+
it("should return null for payload when index is out of range", () => {
|
|
204
|
+
const ext = prepareRefineData();
|
|
205
|
+
assert.strictEqual(ext.workItemPayload(tryAsU64(99)), null);
|
|
206
|
+
});
|
|
207
|
+
// guard against silent accidental changes to the helpers — tryAsU32 ensures
|
|
208
|
+
// encoded lengths match GP's S(w) spec.
|
|
209
|
+
it("uses unsigned little-endian u32 for payload length regardless of platform", () => {
|
|
210
|
+
const items = [buildWorkItem({ service: 1, payloadLen: 0x1234 })];
|
|
211
|
+
const ext = prepareRefineData({ items });
|
|
212
|
+
const one = ext.oneWorkItem(tryAsU64(0));
|
|
213
|
+
assert.ok(one !== null);
|
|
214
|
+
const payloadLen = new DataView(one.raw.buffer, one.raw.byteOffset + 58, 4).getUint32(0, true);
|
|
215
|
+
assert.strictEqual(payloadLen, 0x1234);
|
|
216
|
+
// tryAsU32 would throw on negative values
|
|
217
|
+
assert.doesNotThrow(() => tryAsU32(0x1234));
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type Segment, type SegmentIndex, type ServiceId } from "#@typeberry/block";
|
|
2
2
|
import type { BytesBlob } from "#@typeberry/bytes";
|
|
3
|
+
import type { PvmBackend } from "#@typeberry/config";
|
|
3
4
|
import type { Blake2bHash } from "#@typeberry/hash";
|
|
4
|
-
import { type MachineId, type MachineResult, type MemoryOperation,
|
|
5
|
-
import type
|
|
6
|
-
import type
|
|
7
|
-
import type
|
|
8
|
-
import type
|
|
5
|
+
import { type MachineId, type MachineResult, type MemoryOperation, NoMachineError, type PagesError, type PeekPokeError, type ProgramCounter, type RefineExternalities, SegmentExportError, type ZeroVoidError } from "#@typeberry/jam-host-calls";
|
|
6
|
+
import { type U64 } from "#@typeberry/numbers";
|
|
7
|
+
import { type HostCallMemory, HostCallRegisters } from "#@typeberry/pvm-host-calls";
|
|
8
|
+
import { type BigGas } from "#@typeberry/pvm-interface";
|
|
9
|
+
import { type ProgramDecoderError } from "#@typeberry/pvm-interpreter";
|
|
9
10
|
import type { State } from "#@typeberry/state";
|
|
10
11
|
import { type OK, Result } from "#@typeberry/utils";
|
|
11
12
|
/**
|
|
@@ -18,8 +19,15 @@ export type RefineExternalitiesParams = {
|
|
|
18
19
|
lookupState: State;
|
|
19
20
|
/** Export offset -- sum of exports from prior work items in this package. */
|
|
20
21
|
exportOffset: number;
|
|
22
|
+
/**
|
|
23
|
+
* PVM backend to use for creating inner PVM instances.
|
|
24
|
+
* NIT: Could accept PVMInstanceManager
|
|
25
|
+
*/
|
|
26
|
+
pvmBackend: PvmBackend;
|
|
21
27
|
};
|
|
22
28
|
export declare class RefineExternalitiesImpl implements RefineExternalities {
|
|
29
|
+
/** Inner PVM instances sorted by MachineId. */
|
|
30
|
+
private machines;
|
|
23
31
|
/** Service being refined (used as default for historicalLookup). */
|
|
24
32
|
private readonly currentServiceId;
|
|
25
33
|
/** State at the lookup anchor for preimage lookups. */
|
|
@@ -28,17 +36,19 @@ export declare class RefineExternalitiesImpl implements RefineExternalities {
|
|
|
28
36
|
private readonly exportedSegments;
|
|
29
37
|
/** Offset for segment indexing (sum of exports from prior items). */
|
|
30
38
|
private readonly exportOffset;
|
|
39
|
+
/** PVM backend for creating inner machines. */
|
|
40
|
+
private readonly pvmBackend;
|
|
31
41
|
static create(params: RefineExternalitiesParams): RefineExternalitiesImpl;
|
|
32
42
|
private constructor();
|
|
33
43
|
getExportedSegments(): readonly Segment[];
|
|
34
|
-
machineExpunge(
|
|
44
|
+
machineExpunge(machineIndex: MachineId): Promise<Result<ProgramCounter, NoMachineError>>;
|
|
35
45
|
machinePages(_machineIndex: MachineId, _pageStart: U64, _pageCount: U64, _requestType: MemoryOperation | null): Promise<Result<OK, PagesError>>;
|
|
36
46
|
machineVoidPages(_machineIndex: MachineId, _pageStart: U64, _pageCount: U64): Promise<Result<OK, ZeroVoidError>>;
|
|
37
47
|
machineZeroPages(_machineIndex: MachineId, _pageStart: U64, _pageCount: U64): Promise<Result<OK, ZeroVoidError>>;
|
|
38
48
|
machinePeekFrom(_machineIndex: MachineId, _destinationStart: U64, _sourceStart: U64, _length: U64, _destination: HostCallMemory): Promise<Result<OK, PeekPokeError>>;
|
|
39
49
|
machinePokeInto(_machineIndex: MachineId, _sourceStart: U64, _destinationStart: U64, _length: U64, _source: HostCallMemory): Promise<Result<OK, PeekPokeError>>;
|
|
40
|
-
machineInit(
|
|
41
|
-
machineInvoke(
|
|
50
|
+
machineInit(code: BytesBlob, programCounter: ProgramCounter): Promise<Result<MachineId, ProgramDecoderError>>;
|
|
51
|
+
machineInvoke(machineIndex: MachineId, gas: BigGas, registers: HostCallRegisters): Promise<Result<MachineResult, NoMachineError>>;
|
|
42
52
|
exportSegment(segment: Segment): Result<SegmentIndex, SegmentExportError>;
|
|
43
53
|
historicalLookup(serviceId: ServiceId | null, hash: Blake2bHash): Promise<BytesBlob | null>;
|
|
44
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refine.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/in-core/externalities/refine.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,SAAS,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"refine.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/in-core/externalities/refine.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { MAX_NUMBER_OF_EXPORTS_WP, tryAsSegmentIndex, } from "#@typeberry/block";
|
|
2
|
-
import {
|
|
2
|
+
import { SortedArray } from "#@typeberry/collections";
|
|
3
|
+
import { NoMachineError, SegmentExportError, tryAsMachineId, tryAsProgramCounter, } from "#@typeberry/jam-host-calls";
|
|
4
|
+
import { tryAsU64 } from "#@typeberry/numbers";
|
|
5
|
+
import { Ordering } from "#@typeberry/ordering";
|
|
6
|
+
import { HostCallRegisters, PvmInstanceManager } from "#@typeberry/pvm-host-calls";
|
|
7
|
+
import { Status, tryAsBigGas, tryAsGas } from "#@typeberry/pvm-interface";
|
|
8
|
+
import { ProgramDecoder } from "#@typeberry/pvm-interpreter";
|
|
3
9
|
import { Result } from "#@typeberry/utils";
|
|
10
|
+
/** Used when searching by MachineId only — the comparator ignores this field. */
|
|
11
|
+
const NULL_INTERPRETER = undefined;
|
|
12
|
+
const machineComparator = (a, b) => {
|
|
13
|
+
if (a[0] < b[0]) {
|
|
14
|
+
return Ordering.Less;
|
|
15
|
+
}
|
|
16
|
+
if (a[0] > b[0]) {
|
|
17
|
+
return Ordering.Greater;
|
|
18
|
+
}
|
|
19
|
+
return Ordering.Equal;
|
|
20
|
+
};
|
|
4
21
|
export class RefineExternalitiesImpl {
|
|
22
|
+
/** Inner PVM instances sorted by MachineId. */
|
|
23
|
+
machines = SortedArray.fromSortedArray(machineComparator);
|
|
5
24
|
/** Service being refined (used as default for historicalLookup). */
|
|
6
25
|
currentServiceId;
|
|
7
26
|
/** State at the lookup anchor for preimage lookups. */
|
|
@@ -10,6 +29,8 @@ export class RefineExternalitiesImpl {
|
|
|
10
29
|
exportedSegments = [];
|
|
11
30
|
/** Offset for segment indexing (sum of exports from prior items). */
|
|
12
31
|
exportOffset;
|
|
32
|
+
/** PVM backend for creating inner machines. */
|
|
33
|
+
pvmBackend;
|
|
13
34
|
static create(params) {
|
|
14
35
|
return new RefineExternalitiesImpl(params);
|
|
15
36
|
}
|
|
@@ -17,12 +38,20 @@ export class RefineExternalitiesImpl {
|
|
|
17
38
|
this.currentServiceId = params.currentServiceId;
|
|
18
39
|
this.lookupState = params.lookupState;
|
|
19
40
|
this.exportOffset = params.exportOffset;
|
|
41
|
+
this.pvmBackend = params.pvmBackend;
|
|
20
42
|
}
|
|
21
43
|
getExportedSegments() {
|
|
22
44
|
return this.exportedSegments;
|
|
23
45
|
}
|
|
24
|
-
machineExpunge(
|
|
25
|
-
|
|
46
|
+
machineExpunge(machineIndex) {
|
|
47
|
+
// We just care about machineIndex
|
|
48
|
+
const entry = this.machines.findExact([machineIndex, NULL_INTERPRETER]);
|
|
49
|
+
if (entry === undefined) {
|
|
50
|
+
return Promise.resolve(Result.error(NoMachineError, () => `Machine not found (id: ${machineIndex})`));
|
|
51
|
+
}
|
|
52
|
+
const pc = tryAsProgramCounter(entry[1].getPC());
|
|
53
|
+
this.machines.removeOne(entry);
|
|
54
|
+
return Promise.resolve(Result.ok(pc));
|
|
26
55
|
}
|
|
27
56
|
machinePages(_machineIndex, _pageStart, _pageCount, _requestType) {
|
|
28
57
|
throw new Error("Method not implemented.");
|
|
@@ -39,11 +68,61 @@ export class RefineExternalitiesImpl {
|
|
|
39
68
|
machinePokeInto(_machineIndex, _sourceStart, _destinationStart, _length, _source) {
|
|
40
69
|
throw new Error("Method not implemented.");
|
|
41
70
|
}
|
|
42
|
-
machineInit(
|
|
43
|
-
|
|
71
|
+
async machineInit(code, programCounter) {
|
|
72
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/346400346400?v=0.7.2
|
|
73
|
+
const deblobResult = ProgramDecoder.deblob(code.raw);
|
|
74
|
+
if (deblobResult.isError) {
|
|
75
|
+
return Result.error(deblobResult.error, deblobResult.details);
|
|
76
|
+
}
|
|
77
|
+
const manager = await PvmInstanceManager.new(this.pvmBackend);
|
|
78
|
+
const innerPvm = await manager.getInstance();
|
|
79
|
+
innerPvm.resetGeneric(code.raw, Number(programCounter), tryAsGas(0));
|
|
80
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/348c00348c00?v=0.7.2
|
|
81
|
+
// Binary search for the minimal free MachineId
|
|
82
|
+
const arr = this.machines.array;
|
|
83
|
+
let low = 0;
|
|
84
|
+
let high = arr.length;
|
|
85
|
+
while (low < high) {
|
|
86
|
+
const mid = (low + high) >> 1;
|
|
87
|
+
if (arr[mid][0] > BigInt(mid)) {
|
|
88
|
+
high = mid;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
low = mid + 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const machineId = tryAsMachineId(low);
|
|
95
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/340501340b01?v=0.7.2
|
|
96
|
+
this.machines.insert([machineId, innerPvm]);
|
|
97
|
+
return Result.ok(machineId);
|
|
44
98
|
}
|
|
45
|
-
machineInvoke(
|
|
46
|
-
|
|
99
|
+
machineInvoke(machineIndex, gas, registers) {
|
|
100
|
+
const entry = this.machines.findExact([machineIndex, NULL_INTERPRETER]);
|
|
101
|
+
if (entry === undefined) {
|
|
102
|
+
return Promise.resolve(Result.error(NoMachineError, () => `Machine not found (id: ${machineIndex})`));
|
|
103
|
+
}
|
|
104
|
+
const innerPvm = entry[1];
|
|
105
|
+
// Prepare inner PVM
|
|
106
|
+
innerPvm.registers.setAllEncoded(registers.getEncoded());
|
|
107
|
+
innerPvm.gas.set(gas);
|
|
108
|
+
// Execute program
|
|
109
|
+
innerPvm.runProgram();
|
|
110
|
+
// Status
|
|
111
|
+
const status = innerPvm.getStatus();
|
|
112
|
+
const exitParam = innerPvm.getExitParam() ?? 0;
|
|
113
|
+
const remainingGas = tryAsBigGas(innerPvm.gas.get());
|
|
114
|
+
const outRegisters = HostCallRegisters.fromRaw(new Uint8Array(innerPvm.registers.getAllEncoded()));
|
|
115
|
+
let machineStatus;
|
|
116
|
+
if (status === Status.HOST) {
|
|
117
|
+
machineStatus = { status, hostCallIndex: tryAsU64(exitParam) };
|
|
118
|
+
}
|
|
119
|
+
else if (status === Status.FAULT) {
|
|
120
|
+
machineStatus = { status, address: tryAsU64(exitParam) };
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
machineStatus = { status };
|
|
124
|
+
}
|
|
125
|
+
return Promise.resolve(Result.ok({ result: machineStatus, gas: remainingGas, registers: outRegisters }));
|
|
47
126
|
}
|
|
48
127
|
exportSegment(segment) {
|
|
49
128
|
// https://graypaper.fluffylabs.dev/#/ab2cdbd/335d03335d03?v=0.7.2
|