Michael.W基于Foundry精读Openzeppelin第64期——UUPSUpgradeable.sol

Michael.W基于Foundry精读Openzeppelin第64期——UUPSUpgradeable.sol

      • 0. 版本
        • 0.1 UUPSUpgradeable.sol
      • 1. 目标合约
      • 2. 代码精读
        • 2.1 modifier onlyProxy()
        • 2.2 modifier notDelegated()
        • 2.3 proxiableUUID()
        • 2.4 upgradeTo(address newImplementation) && _authorizeUpgrade(address newImplementation) internal
        • 2.5 upgradeToAndCall(address newImplementation, bytes memory data)
        • 2.6 测试本库带有rollback test的UUPS升级机制

0. 版本

[openzeppelin]:v4.8.3,[forge-std]:v1.5.6

0.1 UUPSUpgradeable.sol

Github: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.3/contracts/proxy/utils/UUPSUpgradeable.sol

UUPSUpgradeable库是专为UUPS代理设计的一种合约升级机制的实现。当本合约被设置为ERC1967Proxy代理合约背后的逻辑合约后,可以对其进行合约升级操作。作为逻辑合约的父合约,本库的安全机制可保证不会因一次错误的升级而打破合约的可升级性。

ERC1967Proxy库详解参见:https://learnblockchain.cn/article/8594

1. 目标合约

继承UUPSUpgradeable合约:

Github: https://github.com/RevelationOfTuring/foundry-openzeppelin-contracts/blob/master/src/proxy/utils/MockUUPSUpgradeable.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;import "openzeppelin-contracts/contracts/proxy/utils/UUPSUpgradeable.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";interface IImplementation {event StorageChanged(uint preValue, uint newValue);
}// specific logic of implementation
contract Implementation is Ownable, IImplementation {// storageuint public i;// initializerfunction __Implementation_init(address owner) external {_transferOwnership(owner);}// logic functionfunction setI(uint newI) external virtual {emit StorageChanged(i, newI);i = newI;}
}contract MockUUPSUpgradeable is UUPSUpgradeable, Implementation {// modified by `onlyOwner`function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}contract MockUUPSUpgradeableNew is MockUUPSUpgradeable {// change the logicfunction setI(uint newI) external override {uint currentI = i;i = currentI + newI;emit StorageChanged(currentI, newI);}
}contract MockUUPSUpgradeableWithWrongProxiableUUID is MockUUPSUpgradeable {// inconsistent proxiable uuidfunction proxiableUUID() external view virtual override notDelegated returns (bytes32) {return bytes32(uint(_IMPLEMENTATION_SLOT) - 1);}
}contract MockUUPSUpgradeableWithRollbackTest is MockUUPSUpgradeable {bytes32 private constant _ROLLBACK_SLOT = bytes32(uint(keccak256("eip1967.proxy.rollback")) - 1);function upgradeTo(address newImplementation) external override onlyProxy {_authorizeUpgrade(newImplementation);_upgradeToAndCallUUPSWithRollbackTest(newImplementation,"",false);}function upgradeToAndCall(address newImplementation, bytes memory data) external payable override onlyProxy {_authorizeUpgrade(newImplementation);_upgradeToAndCallUUPSWithRollbackTest(newImplementation,data,true);}// do rollback test both in {upgradeTo} and {upgradeToAndCall}function _upgradeToAndCallUUPSWithRollbackTest(address newImplementation,bytes memory data,bool forceCall) private {address preImplementation = _getImplementation();// upgrade to and check UUPS on the new implementation with setup call first_upgradeToAndCallUUPS(newImplementation, data, forceCall);StorageSlot.BooleanSlot storage isInRollbackTest = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);// go into rollback testisInRollbackTest.value = true;// upgrade to the pre-implementation from the new implementation without setup call_upgradeToAndCallUUPS(preImplementation, "", false);require(preImplementation == _getImplementation(), "fail to recover pre-implementation in rollback test");// upgrade to the new implementation again without setup call_upgradeToAndCallUUPS(newImplementation, "", false);// get out of rollback testisInRollbackTest.value = false;}
}contract MockUUPSUpgradeableWithRollbackTestNew is MockUUPSUpgradeableWithRollbackTest {// change the logicfunction setI(uint newI) external override {uint currentI = i;i = currentI + newI;emit StorageChanged(currentI, newI);}
}

全部foundry测试合约:

Github: https://github.com/RevelationOfTuring/foundry-openzeppelin-contracts/blob/master/test/proxy/utils/UUPSUpgradeable.t.sol

2. 代码精读

2.1 modifier onlyProxy()

该修饰器用于检查调用其所修饰函数的方式是delegatecall,并校验调用的上下文是一个类ERC1967的代理合约且本逻辑合约是其背后设置的逻辑合约。

注:这个类ERC1967的代理合约只包括将本逻辑合约设置为其背后逻辑合约的UUPS代理或透明代理,而ERC1167最小代理合约(即Clones)通常是无法通过该修饰器的检验的。

ERC1167最小代理合约详解参见:https://learnblockchain.cn/article/8507

    // 本逻辑合约地址// 注:由于是immutable类型常量,在逻辑合约部署时就会将逻辑合约地址以字节码的形式存在链上address private immutable __self = address(this);modifier onlyProxy() {// 校验调用上下文中的本合约地址不是本逻辑合约地址,// 即校验该调用为delegatecallrequire(address(this) != __self, "Function must be called through delegatecall");// 要求调用上下文中调用_getImplementation()返回地址为本逻辑合约地址,// 即校验调用上下文是一个类ERC1967的代理合约且本逻辑合约就是其背后的逻辑合约require(_getImplementation() == __self, "Function must be called through active proxy");// 执行被修饰函数的逻辑_;}
2.2 modifier notDelegated()

该修饰器用于检查调用其所修饰函数的方式非delegatecall,即修饰一个只能在本逻辑合约直接调用而无法从代理合约委托调用的函数。

    modifier notDelegated() {// 校验调用上下文中的本合约地址是本逻辑合约地址,// 即校验该调用为非delegatecallrequire(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");// 执行被修饰函数的逻辑_;}
2.3 proxiableUUID()

返回用于存储逻辑合约地址的slot号。本函数是ERC1822中proxiableUUID()的实现,用于检查合约升级时新旧逻辑合约的兼容性。

注:指向逻辑合约的代理合约不能做逻辑合约,因为这可能在升级过程中引发自己delegatecall自己的情况。该情况会导致gas耗尽从而阻塞合约升级。

例子:

  1. 假设代理合约A -> 逻辑合约B,现在A要将逻辑合约升级更换为代理合约A自身;

  2. 假设代理合约A -> 逻辑合约B(B也是一个代理合约),代理合约B -> 逻辑合约C,现在B要将其逻辑合约升级更换为A。

为了防止在合约升级过程中出现自己delegatecall自己的情况,将proxiableUUID()通过修饰器notDelegated限定为不可delegatecall。

    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {// 返回ERC1967中规定的用于存储逻辑合约地址的slot号// 注:ERC1967Upgrade._IMPLEMENTATION_SLOT详解参见:https://learnblockchain.cn/article/8581return _IMPLEMENTATION_SLOT;}

foundry代码验证:

contract UUPSUpgradeableTest is Test {bytes32 private constant _IMPLEMENTATION_SLOT = bytes32(uint(keccak256("eip1967.proxy.implementation")) - 1);MockUUPSUpgradeable private _testing = new MockUUPSUpgradeable();function test_ProxiableUUID() external {assertEq(_testing.proxiableUUID(), _IMPLEMENTATION_SLOT);// revert with a delegatecallMockUUPSUpgradeable proxy = MockUUPSUpgradeable(address(new ERC1967Proxy(address(_testing), "")));vm.expectRevert("UUPSUpgradeable: must not be called through delegatecall");proxy.proxiableUUID();}
}
2.4 upgradeTo(address newImplementation) && _authorizeUpgrade(address newImplementation) internal
  • upgradeTo(address newImplementation):调用类ERC1967的代理合约,将代理合约背后的原逻辑合约升级为newImplementation;
  • _authorizeUpgrade(address newImplementation) internal:用于校验msg.sender是否具有合约升级权限的函数。该函数为virtual,需要在子类合约中进行函数实现。通常可使用Openzeppelin的AccessControl库Ownable库对升级权限进行管理和约束。

注:

  • AccessControl库详解参见:https://learnblockchain.cn/article/6632
  • Ownable库详解参见:https://learnblockchain.cn/article/6576
    function upgradeTo(address newImplementation) external virtual onlyProxy {// 校验msg.sender是否具有合约升级权限_authorizeUpgrade(newImplementation);// 调用ERC1967Upgrade._upgradeToAndCallUUPS(),将类ERC1967代理合约背后的逻辑合约地址升级更换为newImplementation并对其进行UUPS安全检查。// 注:ERC1967Upgrade._upgradeToAndCallUUPS()详解参见:https://learnblockchain.cn/article/8581_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);}function _authorizeUpgrade(address newImplementation) internal virtual;

foundry代码验证:

contract UUPSUpgradeableTest is Test, IImplementation, IERC1967 {MockUUPSUpgradeable private _testing = new MockUUPSUpgradeable();MockUUPSUpgradeableNew private _implementationNew = new MockUUPSUpgradeableNew();MockUUPSUpgradeableWithWrongProxiableUUID private _implementationNewWithWrongProxiableUUID = new MockUUPSUpgradeableWithWrongProxiableUUID();function test_UpgradeTo() external {// case 1: pass// deploy proxy with a setup calladdress proxyAddress = address(new ERC1967Proxy(address(_testing),abi.encodeCall(_testing.__Implementation_init, (address(this)))));MockUUPSUpgradeable proxyAsMockUUPSUpgradeable = MockUUPSUpgradeable(proxyAddress);// check setup callassertEq(proxyAsMockUUPSUpgradeable.owner(), address(this));// call on proxyuint newI = 1024;vm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(0, newI);proxyAsMockUUPSUpgradeable.setI(newI);assertEq(proxyAsMockUUPSUpgradeable.i(), newI);// upgrade to new implementationvm.expectEmit(proxyAddress);emit IERC1967.Upgraded(address(_implementationNew));proxyAsMockUUPSUpgradeable.upgradeTo(address(_implementationNew));MockUUPSUpgradeableNew proxyAsMockUUPSUpgradeableNew = MockUUPSUpgradeableNew(proxyAddress);// check storageassertEq(proxyAsMockUUPSUpgradeableNew.i(), newI);// call new logicvm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(newI, newI);proxyAsMockUUPSUpgradeableNew.setI(newI);assertEq(proxyAsMockUUPSUpgradeableNew.i(), newI + newI);// case 2: revert if not pass {_authorizeUpgrade}address auth = address(1024);proxyAsMockUUPSUpgradeable = MockUUPSUpgradeable(address(new ERC1967Proxy(address(_testing),abi.encodeCall(_testing.__Implementation_init, (auth)))));vm.expectRevert("Ownable: caller is not the owner");proxyAsMockUUPSUpgradeable.upgradeTo(address(_implementationNew));// case 3: revert if the new implementation has an inconsistent proxiable uuidproxyAsMockUUPSUpgradeable = MockUUPSUpgradeable(address(new ERC1967Proxy(address(_testing),abi.encodeCall(_testing.__Implementation_init, (address(this))))));vm.expectRevert("ERC1967Upgrade: unsupported proxiableUUID");proxyAsMockUUPSUpgradeable.upgradeTo(address(_implementationNewWithWrongProxiableUUID));// case 4: revert if the new implementation has no {proxiableUUID}vm.expectRevert("ERC1967Upgrade: new implementation is not UUPS");proxyAsMockUUPSUpgradeable.upgradeTo(address(this));// case 5: revert with no msg if the new implementation address is an EOAvm.expectRevert();proxyAsMockUUPSUpgradeable.upgradeTo(address(1024));// case 6: revert if call {upgradeTo} directlyvm.expectRevert("Function must be called through delegatecall");_testing.upgradeTo(address(this));// case 7: revert if the context of delegatecall is not an active proxyvm.expectRevert("Function must be called through active proxy");Address.functionDelegateCall(address(_testing),abi.encodeCall(_testing.upgradeTo, (address(_implementationNew))));}
}
2.5 upgradeToAndCall(address newImplementation, bytes memory data)

调用类ERC1967的代理合约,将代理合约背后的原逻辑合约升级为newImplementation并随后再执行一个额外的到新逻辑合约的delegatecall。

    function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {// 校验msg.sender是否具有合约升级权限_authorizeUpgrade(newImplementation);// 调用ERC1967Upgrade._upgradeToAndCallUUPS(),将类ERC1967代理合约背后的逻辑合约地址升级更换为newImplementation并对其进行UUPS安全检查。// 随后再以data为calldata执行一个额外的到新逻辑合约的delegatecall。// 注:ERC1967Upgrade._upgradeToAndCallUUPS()详解参见:https://learnblockchain.cn/article/8581_upgradeToAndCallUUPS(newImplementation, data, true);}

foundry代码验证:

contract UUPSUpgradeableTest is Test, IImplementation, IERC1967 {MockUUPSUpgradeable private _testing = new MockUUPSUpgradeable();MockUUPSUpgradeableNew private _implementationNew = new MockUUPSUpgradeableNew();MockUUPSUpgradeableWithWrongProxiableUUID private _implementationNewWithWrongProxiableUUID = new MockUUPSUpgradeableWithWrongProxiableUUID();function test_UpgradeToAndCall() external {// case 1: pass// deploy proxy with a setup calladdress proxyAddress = address(new ERC1967Proxy(address(_testing),abi.encodeCall(_testing.__Implementation_init, (address(this)))));MockUUPSUpgradeable proxyAsMockUUPSUpgradeable = MockUUPSUpgradeable(proxyAddress);assertEq(proxyAsMockUUPSUpgradeable.owner(), address(this));uint newI = 1024;proxyAsMockUUPSUpgradeable.setI(newI);assertEq(proxyAsMockUUPSUpgradeable.i(), newI);// upgrade to new implementation with a setup callvm.expectEmit(proxyAddress);emit IERC1967.Upgraded(address(_implementationNew));emit IImplementation.StorageChanged(newI, newI);bytes memory data = abi.encodeCall(_implementationNew.setI,(newI));proxyAsMockUUPSUpgradeable.upgradeToAndCall(address(_implementationNew),data);MockUUPSUpgradeableNew proxyAsMockUUPSUpgradeableNew = MockUUPSUpgradeableNew(proxyAddress);// check storageassertEq(proxyAsMockUUPSUpgradeableNew.i(), newI + newI);// call new logicvm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(newI + newI, newI);proxyAsMockUUPSUpgradeableNew.setI(newI);assertEq(proxyAsMockUUPSUpgradeableNew.i(), newI + newI + newI);// case 2: revert if not pass {_authorizeUpgrade}address auth = address(1024);proxyAsMockUUPSUpgradeable = MockUUPSUpgradeable(address(new ERC1967Proxy(address(_testing),abi.encodeCall(_testing.__Implementation_init, (auth)))));vm.expectRevert("Ownable: caller is not the owner");proxyAsMockUUPSUpgradeable.upgradeToAndCall(address(_implementationNew),data);// case 3: revert if the new implementation has an inconsistent proxiable uuidproxyAsMockUUPSUpgradeable = MockUUPSUpgradeable(address(new ERC1967Proxy(address(_testing),abi.encodeCall(_testing.__Implementation_init, (address(this))))));vm.expectRevert("ERC1967Upgrade: unsupported proxiableUUID");proxyAsMockUUPSUpgradeable.upgradeToAndCall(address(_implementationNewWithWrongProxiableUUID),data);// case 4: revert if the new implementation has no {proxiableUUID}vm.expectRevert("ERC1967Upgrade: new implementation is not UUPS");proxyAsMockUUPSUpgradeable.upgradeToAndCall(address(this),data);// case 5: revert with no msg if the new implementation address is an EOAvm.expectRevert();proxyAsMockUUPSUpgradeable.upgradeToAndCall(address(1024),data);// case 6: revert if call {upgradeToAndCall} directlyvm.expectRevert("Function must be called through delegatecall");_testing.upgradeToAndCall(address(this),data);// case 7: revert if the context of delegatecall is not an active proxyvm.expectRevert("Function must be called through active proxy");Address.functionDelegateCall(address(_testing),abi.encodeCall(_testing.upgradeToAndCall,(address(_implementationNew), data)));}
}
2.6 测试本库带有rollback test的UUPS升级机制

foundry代码验证:

contract UUPSUpgradeableTest is Test, IImplementation, IERC1967 {MockUUPSUpgradeableWithRollbackTest private _implementationWithRollbackTest = new MockUUPSUpgradeableWithRollbackTest();MockUUPSUpgradeableWithRollbackTestNew private _implementationWithRollbackTestNew = new MockUUPSUpgradeableWithRollbackTestNew();function test_UpgradeWithUUPSRollbackTest() external {// case 1: test {upgradeTo} with UUPS rollback test// deploy proxy with a setup calladdress proxyAddress = address(new ERC1967Proxy(address(_implementationWithRollbackTest),abi.encodeCall(_implementationWithRollbackTest.__Implementation_init, (address(this)))));MockUUPSUpgradeableWithRollbackTest proxyAsMockUUPSUpgradeableWithRollbackTest = MockUUPSUpgradeableWithRollbackTest(proxyAddress);// check setup callassertEq(proxyAsMockUUPSUpgradeableWithRollbackTest.owner(), address(this));// call on proxyuint newI = 1024;vm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(0, newI);proxyAsMockUUPSUpgradeableWithRollbackTest.setI(newI);assertEq(proxyAsMockUUPSUpgradeableWithRollbackTest.i(), newI);// upgrade to new implementationvm.expectEmit(proxyAddress);emit IERC1967.Upgraded(address(_implementationWithRollbackTestNew));proxyAsMockUUPSUpgradeableWithRollbackTest.upgradeTo(address(_implementationWithRollbackTestNew));MockUUPSUpgradeableWithRollbackTestNew proxyAsMockUUPSUpgradeableWithRollbackTestNew = MockUUPSUpgradeableWithRollbackTestNew(proxyAddress);// check storageassertEq(proxyAsMockUUPSUpgradeableWithRollbackTestNew.i(), newI);// call new logicvm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(newI, newI);proxyAsMockUUPSUpgradeableWithRollbackTestNew.setI(newI);assertEq(proxyAsMockUUPSUpgradeableWithRollbackTestNew.i(), newI + newI);// case 2: test {upgradeToAndCall} with UUPS rollback test// deploy proxy with a setup callproxyAddress = address(new ERC1967Proxy(address(_implementationWithRollbackTest),abi.encodeCall(_implementationWithRollbackTest.__Implementation_init, (address(this)))));proxyAsMockUUPSUpgradeableWithRollbackTest = MockUUPSUpgradeableWithRollbackTest(proxyAddress);// check setup callassertEq(proxyAsMockUUPSUpgradeableWithRollbackTest.owner(), address(this));// call on proxynewI = 1024;vm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(0, newI);proxyAsMockUUPSUpgradeableWithRollbackTest.setI(newI);assertEq(proxyAsMockUUPSUpgradeableWithRollbackTest.i(), newI);// upgrade to new implementation with a setup callvm.expectEmit(proxyAddress);emit IERC1967.Upgraded(address(_implementationWithRollbackTestNew));emit IImplementation.StorageChanged(newI, newI);proxyAsMockUUPSUpgradeableWithRollbackTest.upgradeToAndCall(address(_implementationWithRollbackTestNew),abi.encodeCall(_implementationWithRollbackTestNew.setI,(newI)));proxyAsMockUUPSUpgradeableWithRollbackTestNew = MockUUPSUpgradeableWithRollbackTestNew(proxyAddress);// check storageassertEq(proxyAsMockUUPSUpgradeableWithRollbackTestNew.i(), newI + newI);// call new logicvm.expectEmit(proxyAddress);emit IImplementation.StorageChanged(newI + newI, newI);proxyAsMockUUPSUpgradeableWithRollbackTestNew.setI(newI);assertEq(proxyAsMockUUPSUpgradeableWithRollbackTestNew.i(), newI + newI + newI);}
}

ps:
本人热爱图灵,热爱中本聪,热爱V神。
以下是我个人的公众号,如果有技术问题可以关注我的公众号来跟我交流。
同时我也会在这个公众号上每周更新我的原创文章,喜欢的小伙伴或者老伙计可以支持一下!
如果需要转发,麻烦注明作者。十分感谢!

在这里插入图片描述

公众号名称:后现代泼痞浪漫主义奠基人

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/46944.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux服务器登录mysql无异常,本地登录报1045 -Access denied for user

1、本地登录linux服务器报“1045 -Access denied for user (用户访问被拒绝)” 造成上面链接问题的原因是,用户权限不足,需要在linux服务器上执行如下2条命令即可 CREATE USER root127.0.0.1 IDENTIFIED BY root123; GRANT ALL P…

新美业和传统美业的区别在哪些方面?连锁美业SaaS收银系统源码

新美业和传统美业在很多方面存在着显著的区别。传统美业通常指的是传统的美容美发行业,而新美业则更多地与科技、数字化和创新相关。随着科技的不断发展和消费者需求的变化,新美业将继续引领美容行业的发展趋势。 以下是传统美业和新美业之间的一些区别…

用 AI 写歌词,让音乐表达与众不同

在音乐的广袤天地中,我们都渴望通过独特的表达来触动人心,展现自我。而如今,AI 技术的崛起为音乐创作带来了全新的突破,让我们能够以一种前所未有的方式赋予音乐独特的灵魂。 “妙笔生词智能写歌词软件(veve522&#…

Docker缩小镜像体积与搭建LNMP架构

镜像加速地址 {"registry-mirrors": ["https://docker.m.daocloud.io","https://docker.1panel.live"] } daemon.json 配置文件里面 bip 配置项中可以配置docker 的网段 {"graph": "/data/docker", #数据目录&#xff0…

领航Linux UDP:构建高效网络新纪元

欢迎来到 破晓的历程的 博客 ⛺️不负时光,不负己✈️ 文章目录 引言Udp和Tcp的异同相同点不同点总结 1.1、socket1.2、bind1.3、recvfrom1.4、sendto2.1、代码2.1、说明3.1、代码3.2、说明 引言 在前几篇博客中,我们学习了Linux网络编程中的一些概念。…

【数据结构(邓俊辉)学习笔记】高级搜索树02——B树

文章目录 1. 大数据1.1 640 KB1.2 越来越大的数据1.3 越来越小的内存1.4 一秒与一天1.5 分级I/O1.6 1B 1KB 2. 结构2.1 观察体验2.2 多路平衡2.3 还是I/O2.4 深度统一2.5 阶次含义2.6 紧凑表示2.7 BTNode2.8 BTree 3. 查找3.1 算法过程3.2 操作实例3.3 算法实现3.4 主次成本3.…

JAVASE——图书管理系统

JAVASE图书管理系统 主要业务有:管理员(增删改查),会员(借书还书查看记录) 管理员主要有:查看图书,增加图书,修改图书,会员管理,删除图书, 会员主要有&#x…

昇思25天学习打卡营第22天|GAN图像生成

今天是参加昇思25天学习打卡营的第22天,今天打卡的课程是“GAN图像生成”,这里做一个简单的分享。 1.简介 今天来学习“GAN图像生成”,这是一个基础的生成式模型。 生成式对抗网络(Generative Adversarial Networks,GAN)是一种…

Bug:时间字段显示有问题

Bug:时间字段显示有问题 文章目录 Bug:时间字段显示有问题1、问题2、解决方法一:添加注解3、解决方法二:消息转换器自定义对象映射器配置消息转换器 1、问题 ​ 在后端传输时间给前端的时候,发现前端的时间显示有问题…

[Spring] Spring Web MVC案例实战

🌸个人主页:https://blog.csdn.net/2301_80050796?spm1000.2115.3001.5343 🏵️热门专栏: 🧊 Java基本语法(97平均质量分)https://blog.csdn.net/2301_80050796/category_12615970.html?spm1001.2014.3001.5482 🍕 Collection与…

AV1技术学习:Translational Motion Compensation

编码块根据运动矢量在参考帧中找到相应的预测块,如下图所示,当前块的左上角的位置为(x0, y0),在参考帧中找到同样位置(x0, y0)的块,根据运动矢量移动到目标参考块(左上角位置为:(x1, y1))。 AV1…

前端a-tree遇到的问题

在使用a-tree时候,给虚拟滚动的高度,然后展开a-tree滑动一段距离 比如这样 随后你切换页面,在返回这个页面的时候 就会出现这样的bug 解决方法: onBeforeRouteLeave((to, from, next) > {// 可以在路由参数变化时执行的逻辑ke…

白山云荣获信通院“算网安全行业应用优秀案例”奖

日前,在由中国通信标准化协会算网融合产业及标准推进委员会与信通院共同组织召开的“2024年算网融合产业发展大会”上,白山云凭借创新的SD-WAN算网融合方案,荣获“算网安全行业应用优秀案例”奖。 算网融合是多元异构、海量泛在的算力设施&am…

path模块和HTTP协议

一。path模块常用API ./相对路径,/绝对路径 二,HTTP协议 1.请求报文 1.请求行 URL的组成 2.请求头 3.请求体 可以是空:GET请求 可以是字符串,还可以是json:POST请求 2.响应报文 1.响应行 HTTP / 1.1 200 OK H…

VsCode 与远程服务器 ssh免密登录

首先配置信息 加入下列信息 Host qb-zn HostName 8.1xxx.2xx.3xx User root ForwardAgent yes Port 22 IdentityFile ~/.ssh/id_rsa 找到自己的公钥,不带pub是私钥,打死都不能给别人。复制公钥 拿到公钥后,来到远程服务器 vim ~/.ss…

Leetcode—3011. 判断一个数组是否可以变为有序【中等】(__builtin_popcount()、ranges::is_sorted())

2024每日刷题&#xff08;144&#xff09; Leetcode—3011. 判断一个数组是否可以变为有序 O(n)复杂度实现代码 class Solution { public:bool canSortArray(vector<int>& nums) {// 二进制数位下1数目相同的元素就不进行组内排序// 只进行分组// 当前组的值若小于…

人工智能算法工程师(中级)课程12-PyTorch神经网络之LSTM和GRU网络与代码详解1

大家好,我是微学AI,今天给大家介绍一下人工智能算法工程师(中级)课程12-PyTorch神经网络之LSTM和GRU网络与代码详解。在深度学习领域,循环神经网络(RNN)因其处理序列数据的能力而备受关注。然而,传统的RNN存在梯度消失和梯度爆炸的问题,这使得它在长序列任务中的表现不尽…

MySQL--C_C++语言连接访问

Connector/C的使用 首先需要在mysql官网下载C接口库 解压指令 tar -zxvf 压缩包名 下载并解压好后 但是还有比这更优的做法。 这样子手动安装不仅麻烦&#xff0c;还可能存在兼容性的问题。 其实在我们使用yum安装mysql时&#xff0c;大概率会自动帮我们把其他的环境都安装…

【Datawhale AI夏令营】电力需求预测挑战赛 Task01

整个学习活动&#xff0c;将带你从 跑通最简的Baseline&#xff0c;到了解竞赛通用流程、深入各个竞赛环节&#xff0c;精读Baseline与进阶实践 文章目录 一、赛题背景二、赛题任务三、实践步骤学习规划分析思路常见时序场景 task01codecode 解读 一、赛题背景 随着全球经济的…

CSA笔记1-基础知识和目录管理命令

[litonglocalhost ~]$ 是终端提示符&#xff0c;类似于Windows下的cmd的命令行 litong 当前系统登录的用户名 分隔符 localhost 当前机器名称&#xff0c;本地主机 ~ 当前用户的家目录 $ 表示当前用户为普通用户若为#则表示当前用户为超级管理员 su root 切换root权限…