Quy tắc sửa đổi

Tóm tắt

Kiểm tra runtime sau mỗi instruction: chỉ owner mới có thể trừ lamports hoặc sửa đổi dữ liệu, dữ liệu có thể tăng tối đa 10 KiB mỗi instruction, thay đổi owner yêu cầu dữ liệu được khởi tạo bằng không, và cờ executable là không thể đảo ngược.

Solana runtime thực thi các quy tắc này sau khi mỗi instruction được thực thi thông qua các phương thức BorrowedInstructionAccount. Mỗi quy tắc được kiểm tra tại thời điểm sửa đổi, và transaction sẽ bị rollback nếu bất kỳ kiểm tra nào thất bại.

Quy tắc lamports

Quy tắcThực thiLỗi
Chỉ owner mới có thể trừ lamportsset_lamports(): kiểm tra is_owned_by_current_program() khi lamports < currentExternalAccountLamportSpend
Tài khoản read-only không thể thay đổi lamportsset_lamports(): kiểm tra is_writable()ReadonlyLamportChange
Bất kỳ program nào cũng có thể cộng lamports vào tài khoản writableset_lamports(): kiểm tra ownership chỉ áp dụng khi số dư mới nhỏ hơn số dư hiện tại; kiểm tra writable vẫn được áp dụngReadonlyLamportChange
Lamports phải cân bằng trong một instructionTransactionContext::pop(): xác minh get_lamports_delta() == 0UnbalancedInstruction

Quy tắc dữ liệu

Quy tắcThực thiLỗi
Chỉ owner mới có thể sửa đổi dữ liệucan_data_be_changed(): kiểm tra is_owned_by_current_program()ExternalAccountDataModified
Tài khoản read-only không thể sửa đổi dữ liệucan_data_be_changed(): kiểm tra is_writable()ReadonlyDataModified
Chỉ owner mới có thể thay đổi kích thước dữ liệucan_data_be_resized(): kiểm tra is_owned_by_current_program() khi new_len != old_lenAccountDataSizeChanged
Kích thước dữ liệu tối đa: 10 MiBTransactionAccounts::can_data_be_resized(): kiểm tra new_len <= MAX_ACCOUNT_DATA_LENInvalidRealloc
Tăng trưởng tối đa mỗi instruction: 10 KiBDeserialization trong deserialize_parameters_aligned(): kiểm tra post_len - pre_len <= MAX_PERMITTED_DATA_INCREASEInvalidRealloc
Tăng trưởng tối đa mỗi transaction: 20 MiBTransactionAccounts::can_data_be_resized(): kiểm tra tích lũy resize_delta <= MAX_ACCOUNT_DATA_GROWTH_PER_TRANSACTIONMaxAccountsDataAllocationsExceeded

Quy tắc owner

Quy tắcThực thiLỗi
Chỉ owner hiện tại mới có thể chỉ định lại ownerset_owner(): kiểm tra is_owned_by_current_program()ModifiedProgramId
Tài khoản phải có thể ghiset_owner(): kiểm tra is_writable()ModifiedProgramId
Dữ liệu phải được khởi tạo bằng zeroset_owner(): kiểm tra is_zeroed(data)ModifiedProgramId

Quy tắc cờ executable

Quy tắcThực thiLỗi
Tài khoản phải miễn rentset_executable(): kiểm tra rent.is_exempt(lamports, data_len)ExecutableAccountNotRentExempt
Chỉ owner mới có thể đặt cờset_executable(): kiểm tra is_owned_by_current_program()ExecutableModified
Tài khoản phải có thể ghiset_executable(): kiểm tra is_writable()ExecutableModified

Chuyển đổi trạng thái rent

Tài khoản tồn tại ở một trong ba giá trị RentState: Uninitialized (0 lamports), RentPaying (trên 0 nhưng dưới mức tối thiểu miễn rent), và RentExempt (bằng hoặc trên mức tối thiểu). Các chuyển đổi không được phép tạo ra TransactionError::InsufficientFundsForRent.

Runtime thực thi các quy tắc này thông qua transition_allowed():

  • Bất kỳ tài khoản nào cũng có thể chuyển sang Uninitialized (đóng) hoặc RentExempt.
  • Không có tài khoản nào có thể chuyển vào RentPaying từ Uninitialized hoặc RentExempt. Tất cả tài khoản mới phải miễn rent.

Quy tắc borrow tài khoản

Trong quá trình thực thi instruction, runtime thực thi ngữ nghĩa borrow single-writer trên các tài khoản. Một program có thể lấy một mutable reference hoặc nhiều immutable reference đến một tài khoản, nhưng không thể có cả hai cùng lúc. Nếu một program cố gắng borrow một tài khoản đã được mutably borrow (hoặc mutably borrow một tài khoản đã được immutably borrow), instruction sẽ thất bại với AccountBorrowFailed thông qua try_borrow()try_borrow_mut(). Nếu một instruction hoàn thành trong khi một borrow vẫn còn tồn tại, runtime trả về AccountBorrowOutstanding trong TransactionContext::pop().

Is this page helpful?

Mục lục

Chỉnh sửa trang

Quản lý bởi

© 2026 Solana Foundation.
Đã đăng ký bản quyền.
Kết nối