Skip to main content

Command Palette

Search for a command to run...

Solana 实现链上数据存储器

Published
3 min readView as Markdown
C
酷愛計算機技術Ardently Love Computer Technology 長期關註反洗錢反欺詐Long-term Focus on Anti-Money Laundering and Anti-Fraud 精通支付結算的技術、系統、流程和製度Proficient in the Technology, System, Process and Institution of Payment and Settlement

从零开始搭建,即便对照讲解修改配置文件 Cargo.toml 编译时依然报错,且各种尝试都无法解决

# cargo build-sbf
error: failed to download `constant_time_eq v0.4.2`

Caused by:
  unable to get packages from source

Caused by:
  failed to download replaced source registry `crates-io`

Caused by:
  failed to parse manifest at `/root/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/constant_time_eq-0.4.2/Cargo.toml`

Caused by:
  feature `edition2024` is required

  The package requires the Cargo feature called `edition2024`, but that feature is not stabilized in this version of Cargo (1.84.0 (12fe57a9d 2025-04-07)).
  Consider trying a more recent nightly release.
  See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2024 for more information about the status of this feature.

直接从仓库下载完整项目,需要加速器

$ git clone https://github.com/bonujel/pxsol-ss.git
正克隆到 'pxsol-ss'...
致命错误:无法访问 'https://github.com/bonujel/pxsol-ss.git/':Recv failure: 连接被对方重置

$ git clone https://gh-proxy.org/https://github.com/bonujel/pxsol-ss.git
正克隆到 'pxsol-ss'...
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 38 (delta 14), reused 34 (delta 10), pack-reused 0 (from 0)
接收对象中: 100% (38/38), 19.60 KiB | 89.00 KiB/s, 完成.
处理 delta 中: 100% (14/14), 完成.

这时再编译,就不报错了

$ cd pxsol-ss/

$ su root
密码: 

# cargo build-sbf 
    Updating `rsproxy-sparse` index
  Downloaded crossbeam-epoch v0.9.18 (registry `rsproxy-sparse`)
...
   Compiling pxsol-ss v0.1.0 
    Finished `release` profile [optimized] target(s) in 9m 14s

此时项目结构

$ tree -L 2
.
├── Cargo.lock
├── Cargo.toml
├── CLAUDE.md
├── rustfmt.toml
├── src
│   └── lib.rs
├── target
│   ├── CACHEDIR.TAG
│   ├── deploy
│   ├── release
│   └── sbpf-solana-solana
└── tests
    ├── config.py
    ├── __pycache__
    ├── test_read_pda.py
    ├── test_update_pda.py
    ├── test_upgrade.py
    └── test_write.py

8 directories, 11 files

部署到本地网,先开启节点,否则报错。生成 Program Id

# cd target/

# solana program deploy pxsol_ss.so 
Error: AccountNotFound: pubkey=G3JG874izSDSjZ1Awuf975PojmL8RyHYULUYGkTaHv8G: error sending request for url (http://localhost:8899/)

# solana-test-validator 
Ledger location: test-ledger
Log: test-ledger/validator.log
⠉ Initializing...                                                                                                                              Waiting for fees to stabilize 1...
⠂ Initializing...                                                                                                                              Waiting for fees to stabilize 2...
Identity: 7K1gCa683Ebrs1Q8rTAuYPnSAKjJJ4AJ2rWxVgLArL6S
Genesis Hash: BiUKyGcGb1U4mVrRAkAxmGWjRf8p8VZFQf11Sxz3aeJ5
Version: 3.0.13
Shred Version: 29776
Gossip Address: 127.0.0.1:8000
TPU Address: 127.0.0.1:8003
JSON RPC URL: http://127.0.0.1:8899
WebSocket PubSub URL: ws://127.0.0.1:8900

# solana program deploy pxsol_ss.so 
Program Id: G3JG874izSDSjZ1Awuf975PojmL8RyHYULUYGkTaHv8G

Signature: 5X23pUpaDXEkiEZpYrdxS5GVjf3PewjqY1EXG7azJZ3Suc2Jgt1EuAptY1kaNMYn8PLnpko36X3mp2iNtbfX7LHs

按照项目作者说明,测试需要 python311 环境

先安装 conda ,再安装 python311

$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py313_25.9.1-3-Linux-x86_64.sh
--2026-01-15 13:41:52--  https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py313_25.9.1-3-Linux-x86_64.sh
正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:157891003 (151M) [application/octet-stream]
正在保存至: “Miniconda3-py313_25.9.1-3-Linux-x86_64.sh”

Miniconda3-py313_25.9.1-3-Linux-x86 100%[==================================================================>] 150.58M  11.1MB/s  用时 14s     

2026-01-15 13:42:07 (11.0 MB/s) - 已保存 “Miniconda3-py313_25.9.1-3-Linux-x86_64.sh” [157891003/157891003])

$ sh Miniconda3-py313_25.9.1-3-Linux-x86_64.sh 

Welcome to Miniconda3 py313_25.9.1-3

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 
MINICONDA END USER LICENSE AGREEMENT
...

==> For changes to take effect, close and re-open your current shell. <==

Thank you for installing Miniconda3!

$ conda create --name python311 python=3.11
Do you accept the Terms of Service (ToS) for https://repo.anaconda.com/pkgs/main? [(a)ccept/(r)eject/(v)iew]: 
Do you accept the Terms of Service (ToS) for https://repo.anaconda.com/pkgs/r? [(a)ccept/(r)eject/(v)iew]: 
2 channel Terms of Service accepted
Retrieving notices: done
Channels:
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done

Downloading and Extracting Packages:
...
Preparing transaction: done                                                                                                                    
Verifying transaction: done                                                                                                                    
Executing transaction: done                                                                                                                    
#                                                                                                                                              
# To activate this environment, use                                                                                                            
#                                                                                                                                              
#     $ conda activate python311                                                                                                               
#                                                                                                                                              
# To deactivate an active environment, use
#
#     $ conda deactivate

激活 python311 环境,并执行【写入测试】脚本

$ conda activate python311

$ python -V
Python 3.11.14

$ python test_write.py
Traceback (most recent call last):
...
ModuleNotFoundError: No module named 'pxsol'

报错提示【未找到 pxsol 模块】,使用 pip 安装

$ pip install pxsol
Collecting pxsol
  Downloading pxsol-0.5.4-py2.py3-none-any.whl.metadata (8.7 kB)

修改 config.py 文件里的

PROGRAM_ID = 刚刚生成的

WALLET_PATH = /root/.config/solana/id.json

还是有报错

$ python test_read_pda.py 
Traceback (most recent call last):
...
NameError: name 'Pt' is not defined. Did you mean: 'P'?

主要参考

https://github.com/bonujel/pxsol-ss

https://github.com/mohanson/pxsol-ss

https://accu.cc/content/solana/ss_skeleton/

More from this blog

Penetration Test、Python、Weaponization

721 posts

微信 smartcat9999 反欺詐Anti-Fraud 反洗錢Anti-Money Laundering 反逃稅Anti-Tax Evasion 滲透測試Penetration Test 武器化Weaponization